Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Question / Issue


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.


Answer / Solution

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.

Updated: 19. February 2023
Still not using affiliate-toolkit?
Setup takes less than 5 minutes and you can start to import first products!
Learn more about the packagesDownload FREE Version
Still need help?
Submit Your Question
Please give us the details, our support team will get back to you.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram