Woocommerce: Product CSV import filter: wp_set_object_terms for new products

Created on 31 Aug 2017  路  1Comment  路  Source: woocommerce/woocommerce

  • [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate
  • [x] The issue still exists against the latest master branch of WooCommerce on Github
  • [x] I have attempted to find the simplest possible steps to reproduce the issue
  • [ ] I have included a failing test as a pull request (Optional)

Steps to reproduce the issue

  1. use wp_set_object_terms with woocommerce_product_import_pre_insert_product_object when importing A NEW product (for assigning a custom taxonomy term to a new product)
  2. use wp_set_object_terms with woocommerce_product_import_pre_insert_product_object when importing/UPDATING an existing product via ID

code example:
wp_set_object_terms( $object->get_id(), $data['e_product_type'], 'e_product_type' );

Expected/actual behavior

When I follow those steps, I see...
...no term set for a new product, but the correct term set when updating an existing product

I was expecting to see...
...a term set for new as well as updated products

Isolating the problem

  • [x] This bug happens with only WooCommerce plugin active
  • [x] This bug happens with a default WordPress theme active, or Storefront
  • [x] I can reproduce this bug consistently using the steps above

Most helpful comment

use wp_set_object_terms with woocommerce_product_import_pre_insert_product_object when importing A NEW product (for assigning a custom taxonomy term to a new product)

The product hasn't been saved at this point, so there is going to be no post ID for new products. You gotta have a post ID for wp_set_object_terms to work. :)

Use the action right under it: woocommerce_product_import_inserted_product_object

>All comments

use wp_set_object_terms with woocommerce_product_import_pre_insert_product_object when importing A NEW product (for assigning a custom taxonomy term to a new product)

The product hasn't been saved at this point, so there is going to be no post ID for new products. You gotta have a post ID for wp_set_object_terms to work. :)

Use the action right under it: woocommerce_product_import_inserted_product_object

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikejolley picture mikejolley  路  3Comments

luthv picture luthv  路  3Comments

jameskoster picture jameskoster  路  3Comments

maxrice picture maxrice  路  3Comments

richangel picture richangel  路  3Comments