How to choose multi-categories for 1 product ?

Closed

Import WP Addon - WooCommerce Updated 1 month ago 2 Replies

Dung asked 2 months ago on July 18, 2024 at 8:54 am

Example: scrape the urls:

amazon.com/Norton

amazon.com/Internet Security

-> I get “Norton antivirus for 1 PC” product.

 

in mapping field.

1.URL column has Norton-> Norton category

2.URL column has Internet Security-> Internet Security category

As I see, when importing, (URL column has Norton) it will set Norton category for the product, then (URL column has Internet Securit) it will update & change category (from Norton to Internet Security). It means the product has only 1 category after importing. Is It right ?

I want the product has 2 categories : Norton, Internet Security. How to do that ?

J

James replied Support Agent

2 months ago on July 18, 2024 at 9:27 am

Hi Dung,

You can achieve this with a custom method (custom methods/functions should be added to your websites code, or if you are unfamilier with that you can use a plugin like:  https://wordpress.org/plugins/code-snippets/ , making sure the script is "allowed to run everywhere"), instead of using the mapping functionality.

function iwp_map_set_values($input = '')
{
    $parts = explode(',', $input);
    $parts = array_values(array_unique(array_filter(array_map('trim', $parts))));

    $allowed = [
        'Norton' => 'Norton category',
        'Internet Security' => 'Internet Security category',
        // TODO: add new matches here as: 'keywords' => 'result'
    ];

    $tmp = [];
    foreach ($allowed as $v => $r) {
        $tmp[strtolower($v)] = $r;
    }

    $output = [];

    $last = 0;

    foreach ($parts as $part) {

        $lower = strtolower($part);
        foreach ($tmp as $allowed_lc => $allowed_val) {

            if (strpos($lower, $allowed_lc) !== false) {

                $output[] = $allowed_val;
            }
        }
    }

    return implode(',', array_unique($output));
}

You can use this in your importer by replacing your selection e.g. "{1}" with:

[iwp_map_set_values("{1}")]

You can then update the list off allowed options by adding extra items to the end of the array, with a 'keywords' => 'result'

For example:

$allowed = [
    'Norton' => 'Norton category',
    'Internet Security' => 'Internet Security category',
    'Windows Firewall' => 'Windows defender',
    // TODO: add new matches here as: 'keywords' => 'result'
];

James

J

James replied Support Agent

1 month ago on July 28, 2024 at 4:18 pm

Hello Dung

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