Since the categories are listed separately, and are based on IDs, you will need to import them first in a "Taxonomies" import:
On step 2 of the import, choose the "category" element:
On step 3 (the import template), you'll need to save the "id" attribute inside a term meta field named "_category_id":
And, use an IF statement along with a custom PHP function (see documentation) in the "Parent Term" field:
[IF({./@parentId[.!=""]})][my_get_category({./@parentId})][ELSE][ENDIF]
Here's the code for the function:
function my_get_category( $id ) {
$term = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'meta_query' => array(
array(
'key' => '_category_id',
'value' => $id,
'compare' => '='
)
)
)
);
if ( ! empty( $term ) ) {
return $term[0]->slug;
}
}
After you've imported your taxonomies with these settings, you'll be able to retrieve the category names/slugs using the same function when importing your Products:
[my_get_category({categoryId[1]})]
There are a couple of things to keep in mind when importing the attributes for your products:
- The "param" elements can vary in position on each import record, and they use Cyrillic symbols, so you'll need to query them using the instructions here: Query Cyrillic Attribute Values.
- You'll need to manually map each attribute in the import template. It's not possible to dynamically import a varying amount of attributes per-record.
Здравствуйте.
Не знаю, что я делаю неправильно, но часть категорий дублируется со слагом cаtegory-name-2 и именем cаtegory-name, вместо Категори Наме. Подробности на скриншоте http://joxi.ru/GrqndjVcGLoYlm. Возможно, это из-за одинаковых названий подкатегорий в некоторых категориях. Я использую плагин транслитерации Кириллицы.
WP All Import может сопоставлять товары с категориями по слагу, поэтому раньше я импортировал сначала категории из YML файлов, указывая в качестве slug'a ID категории:
<category id="148" parentId="140">Все товары/Спорт и отдых/Скейтбординг/Скейтборды и лонгборды</category>
а потом при импорте товаров тоже указывал category id. Импортировалось правильно, но урлы категорий были в виде site.ru/product-category/148/140, что не очень хорошо, не ЧПУ. Шаблон импорта: https://cloud.mail.ru/public/SXiH/2Ya1CuvTf
Поэтому идея такая: что если импортировать категории и товары как я описал выше, получив site.ru/product-category/148/140, а затем добавить в functions.php код редиректа через хук template_redirect, использовав для создания хука строчки из файла YML с категориями
<category id="148" parentId="140">Все товары/Спорт и отдых/Скейтбординг/Скейтборды и лонгборды</category>
, добавив поиском-заменой нужный код до и после или использовав другой метод замены слага по имени категории.Напишите мне Ваше мнение, если Вам интересен этот вопрос 2816175@mail.ru
Спасибо