Importing categories and subcategories

Closed

Import WP Addon - WooCommerce Updated 4 months ago 7 Replies

Francesca asked 6 months ago on May 31, 2024 at 3:10 pm

Hello,

we need to import product taxonomy based on the category id, how can we set subcategories?

It seems we can’t enable hierarchy, is there a way to manage it?

Attached is an example of the taxonomy.

J

James replied Support Agent

6 months ago on May 31, 2024 at 4:38 pm

Hi Francesca,

Yes this should be possible, From your csv, should the "Raffreddore" category, have he parent category that has the id: 29 ?

James

FN

Francesca replied

6 months ago on May 31, 2024 at 9:39 pm

Hi James,

yes, "Raffreddore" has category id 41 and the parent is 29 (whose parent is 25, etc).

F.

J

James replied Support Agent

6 months ago on June 3, 2024 at 8:20 pm

Hi Francesca,

Sorry it has taken so long to get back to you with a response, the importer currently only allows you to set a full hierarchy when importing taxonomies onto posts via the post template (where you can set a hierarchy character and then set the parent its as : 25 > 29 > 41), however this option has not been added to the term template.

I have been looking into adding a similar option into the term template to provide you with a solution, do you require the full hierarchy, or could you get away with just using the parent id of the current term being imported using the current parent fields (i only say this because you are referencing id's and not slugs or names that can have duplicates)?

James

FN

Francesca replied

5 months ago on June 13, 2024 at 10:11 am

Hi James,

I'm sorry I didn't reply sooner, we received a new CSV and imported all categories and subcategories.

Thanks for your support.

F.

MB

Mike replied

5 months ago on June 19, 2024 at 12:39 pm

Hi James,

 

I am also trying to import product categories with their hierachy and i'm failing. for example i wil to import:

main category/suncat1/subcat2/subcat3/subcat4/subcat5/subcat6/subcat7/subcat8/subcat9/subcat10

can i have a template of how the csv file should look like as i have tried all that i know and it's not working.

 

Thank hey

J

James replied Support Agent

5 months ago on June 22, 2024 at 8:49 pm

Hi Mike,

Based on the attached csv, the only way i could keep import the hierarchy is by using the following code ( it grabs the element of the the end of the list and uses this as the current parent term):

function iwp_arr_extract($input = '', $delimiter = '|', $index = '', $fallback = '')
{
    $data = explode($delimiter, $input);
    $data = array_values(array_map('trim', $data));

    if (intval($index) > -1 && isset($data[$index])) {

        // return specific index
        return $data[$index];
    } elseif ($index == '-1') {

        // return last element
        return end($data);
    }

    // return fallback
    return $fallback;
}

Which i have attached as a custom plugin, once activated you can use it as the parent field (screenshot of parent and parent field type settings attached).

[iwp_arr_extract("{10}", ",", "-1")]

Running the import the first time, will set the correct hierarchy for all but the row "child 10", this is due to the order of the csv, as it does not know about "child 9" as this record has yet to be created at this time.

Ruinng the import for the second time should fix this.

My main question is, why is there no data in any other of the columns e.g. parent.name or parent.slug as this would not require the custom function to work.

James

J

James replied Support Agent

4 months ago on July 16, 2024 at 8:00 pm

Hello Francesca

This ticket is being marked as closed due to inactivity.

If this is not the case, please reply to this ticket to re-open it.

James