Issue importing Woocommerce products with same name subcategory

  • Unknown's avatar

    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

    But instead, 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.

    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.

  • Hi –

    It looks like the site is actually set up on the open source WordPress.org software rather than our managed hosting environment of WordPress.com.

    Please share your site URL so we can confirm.

    Help with WordPress.org comes from https://wordpress.org/support/forums/

  • Unknown's avatar

    Thanks a lot for this clarification. Now I see why I had difficulties in using this blog.

    Yes, I do download WordPress from wordpress.org, so I have to write on their forum.

    I cannot register tho, because it says I still have to confirm my account. There’s no email and I don’t find a contact form on their site to just ask them for another verification email.

    I feel so dumb and demotivated that asking for help is getting this hard…

  • WordPress.org is open-source software and the support is provided by the community on the forums.

    I’d recommend checking the forum for similar threads. This article may also be helpful.
    We won’t be able to help you any further with this issue I’m afraid.

  • The topic ‘Issue importing Woocommerce products with same name subcategory’ is closed to new replies.