Hello,
I would like to extend the lists with the product categories. All products that are created via the list should then be assigned to this product category.
To realize this, we need to access two hooks from affiliate-toolkit.
This code assigns the product category to the list. You may need to replace "productcategory" with your own name.
function atkp_list_register_post_type_list($args) {
$args['taxonomies'] = array('productcategory');
return $args;
}
add_filter('atkp_list_register_post_type', 'atkp_list_register_post_type_list', 10, 1);
Now you can assign the categories to the list.
Now we just need to copy the product categories from the list to the product. We can do that with the following hook:
function atkp_product_autoimport_list($product_list, $list_id) {
foreach($product_list as $product_item) {
$type = $product_item['type'];
if($type == 'productid') {
$product_id = $product_item['value'];
// get an array with the term_ids only
$term_ids = array();
$term_objs = get_the_terms( $list_id, 'productcategory' );
// get_the_terms returns an array of WP_Term objects
foreach ($term_objs as $term_obj)
$term_ids[] = $term_obj->term_id; // get the id from the WP_Term object
if ( count($term_ids) > 0 ){
wp_set_post_terms($product_id, $term_ids, 'productcategory', false);
}
}
}
}
add_action('atkp_product_autoimport', 'atkp_product_autoimport_list', 10, 2);
Again, the "productcategory" name may need to be replaced with your own.