Issue importing Woocommerce products with same name subcategory
-
Hi All,
we have a PHP procedure that automatically imports (through a CRON process every night) all products from a CSV file to our Woocommerce.
The problem is that, when setting subcategories, if there are 2 (or more) of them with the same name, under DIFFERENT parent categories, it automatically gives the product the first one found.
For example, I want to get this:
Medals |-> Silver |--> Large |--> Small |-> Gold |--> Large |--> Small
So, under the parent category “Medals”, there are 2 different subcategories “Silver” and “Gold”. They both have another depth level of subcategories with the same NAME.
Instead, when importing, I get this:
Medals |-> Silver |-> Gold |--> Large |--> Small
So every Silver medal takes “Large” or “Small” subcategory under the “Gold” tree (instead of “Silver” tree) since Gold is the first one found in the CSV and so the first to create “Large” and “Small” subcategories.
It’s like WordPress says “Hey, there’s already a Large subcategory existing, I’m going to put all your products there” ignoring the fact that the parent category is “Silver” instead of “Gold”.
The code creating categories from the CSV is:
$cat = sanitize_text_field($data[2]); $cat = strtolower($cat); $cat2 = sanitize_text_field($data[3]); $cat2 = strtolower($cat2); $cat3 = sanitize_text_field($data[4]); $cat3 = strtolower($cat3); wp_set_object_terms($post_id, $cat, ‘product_cat’); wp_set_object_terms($post_id, $cat2, ‘product_cat’, $append = true ) ; wp_set_object_terms($post_id, $cat3, ‘product_cat’, $append = true ) ;
where $data is an array of values of the CSV file (every row in the CSV is a single product, in this case, a medal).
Sorry for the wall of text but I’ve tried a lot and cannot figure this out.
If I wasn’t clear explaining this, go ahead and tell me!Thanks in advance. Would be really grateful if you have any ideas.
- The topic ‘Issue importing Woocommerce products with same name subcategory’ is closed to new replies.