Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Created April 25, 2020 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kagg-design/3d9d930e6f176bdd6951b7e57227de10 to your computer and use it in GitHub Desktop.
Save kagg-design/3d9d930e6f176bdd6951b7e57227de10 to your computer and use it in GitHub Desktop.
wc1c hooks
<?php
/**
* wc1c_import_product_xml hook
* Prevent processing a product if there is no product in database with same SKU.
* If product with the same SKU found in the db, update _wc1c_guid option to allow product update.
*
* @param array $product
* @param bool $is_full
*
* @return null|array
*/
function ft_wc1c_import_product_xml( $product, $is_full ) {
if ( ! isset( $product['Артикул'] ) || ! isset( $product['Ид'] ) ) {
return null;
}
$post_id = wc1c_post_id_by_meta( '_sku', $product['Артикул'] );
if ( ! $post_id ) {
return null;
}
update_post_meta( $post_id, '_wc1c_guid', $product['Ид'] );
unset( $product['Группы'] );
return $product;
}
add_filter( 'wc1c_import_product_xml', 'ft_wc1c_import_product_xml', 10, 2 );
/**
* wc1c_import_group_xml filter.
* Block import of product categories.
*
* @param $group
* @param $parent_groups
* @param $is_full
*
* @return null
*/
function ft_wc1c_import_group_xml( $group, $parent_groups, $is_full ) {
return null;
}
add_filter( 'wc1c_import_group_xml', 'ft_wc1c_import_group_xml', 10, 3 );
/**
* wc1c_import_preserve_property_fields filer.
* Specify what fields in product to preserve:
* title => post_title
* excerpt => post_excerpt
* content => post_content
*
* @param $fields
* @param $property
* @param $is_full
*
* @return array
*/
function ft_wc1c_import_preserve_product_fields( $fields, $property, $is_full ) {
return array( 'title', 'excerpt', 'body', 'categories' );
}
add_filter( 'wc1c_import_preserve_product_fields', 'ft_wc1c_import_preserve_product_fields', 10, 3 );
/**
* wc1c_before_offers hook
* Fix price update logic, due to simplified format of price in offers0_1.xml
*
* @param $is_full
* @param $names
* @param $depth
* @param $name
*/
function ft_wc1c_before_offers( $is_full, $names, $depth, $name ) {
global $wc1c_price;
unset( $wc1c_price['ИдТипаЦены'] );
}
add_action( 'wc1c_before_offers', 'ft_wc1c_before_offers', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment