Hola, estoy tratando de importar productos utilizando la clase de importador CSV del producto WC, con un complemento personalizado, los productos importan correctamente, pero las categorías y atributos no se están importando, este es mi código:
wp_set_current_user(1);
$mapping = array(
'Type' => 'type',
'SKU' => 'sku',
'Name' => 'name',
'Published' => 'status',
'Is featured?' => 'featured',
'Visibility in catalog' => 'catalog_visibility',
'Description' => 'description',
'Tax status' => 'tax_status',
'In stock?' => 'stock_status',
'Stock' => 'stock_quantity',
'Backorders allowed?' => 'backorders_allowed',
'Sold individually?' => 'sold_individually',
'Weight (g)' => 'weight',
'Allow customer reviews?' => 'reviews_allowed',
'Regular price' => 'regular_price',
'Categories' => 'categories',
'Images' => 'images',
'Attribute 1 name' => 'attributes:name1',
'Attribute 1 value(s)' => 'attributes:value1',
'Attribute 1 visible' => 'attributes:visible1',
'Attribute 1 global' => 'attributes:taxonomy1',
'Attribute 2 name' => 'attribute_2_name',
'Attribute 2 value(s)' => 'attribute_2_value(s)',
'Attribute 2 visible' => 'attribute_2_visible',
'Attribute 2 global' => 'attribute_2_global',
'Attribute 3 name' => 'attribute_3_name',
'Attribute 3 value(s)' => 'attribute_3_value(s)',
'Attribute 3 visible' => 'attribute_3_visible',
'Attribute 3 global' => 'attribute_3_global',
'Attribute 4 name' => 'attribute_4_name',
'Attribute 4 value(s)' => 'attribute_4_value(s)',
'Attribute 4 visible' => 'attribute_4_visible',
'Attribute 4 global' => 'attribute_4_global',
'Attribute 5 name' => 'attribute_5_name',
'Attribute 5 value(s)' => 'attribute_5_value(s)',
'Attribute 5 visible' => 'attribute_5_visible',
'Attribute 5 global' => 'attribute_5_global',
'Attribute 6 name' => 'attribute_6_name',
'Attribute 6 value(s)' => 'attribute_6_value(s)',
'Attribute 6 visible' => 'attribute_6_visible',
'Attribute 6 global' => 'attribute_6_global',
'Attribute 7 name' => 'attribute_7_name',
'Attribute 7 value(s)' => 'attribute_7_value(s)',
'Attribute 7 visible' => 'attribute_7_visible',
'Attribute 7 global' => 'attribute_7_global',
'Attribute 8 name' => 'attribute_8_name',
'Attribute 8 value(s)' => 'attribute_8_value(s)',
'Attribute 8 visible' => 'attribute_8_visible',
'Attribute 8 global' => 'attribute_8_global',
'Attribute 9 name' => 'attribute_9_name',
'Attribute 9 value(s)' => 'attribute_9_value(s)',
'Attribute 9 visible' => 'attribute_9_visible',
'Attribute 9 global' => 'attribute_9_global',
'Attribute 10 name' => 'attribute_10_name',
'Attribute 10 value(s)' => 'attribute_10_value(s)',
'Attribute 10 visible' => 'attribute_10_visible',
'Attribute 10 global' => 'attribute_10_global',
'Attribute 11 name' => 'attribute_11_name',
'Attribute 11 value(s)' => 'attribute_11_value(s)',
'Attribute 11 visible' => 'attribute_11_visible',
'Attribute 11 global' => 'attribute_11_global',
'Attribute 12 name' => 'attribute_12_name',
'Attribute 12 value(s)' => 'attribute_12_value(s)',
'Attribute 12 visible' => 'attribute_12_visible',
'Attribute 12 global' => 'attribute_12_global',
'Attribute 13 name' => 'attribute_13_name',
'Attribute 13 value(s)' => 'attribute_13_value(s)',
'Attribute 13 visible' => 'attribute_13_visible',
'Attribute 13 global' => 'attribute_13_global',
'Attribute 14 name' => 'attribute_14_name',
'Attribute 14 value(s)' => 'attribute_14_value(s)',
'Attribute 14 visible' => 'attribute_14_visible',
'Attribute 14 global' => 'attribute_14_global',
'Attribute 15 name' => 'attribute_15_name',
'Attribute 15 value(s)' => 'attribute_15_value(s)',
'Attribute 15 visible' => 'attribute_15_visible',
'Attribute 15 global' => 'attribute_15_global',
'Attribute 16 name' => 'attribute_16_name',
'Attribute 16 value(s)' => 'attribute_16_value(s)',
'Attribute 16 visible' => 'attribute_16_visible',
'Attribute 16 global' => 'attribute_16_global',
'Attribute 17 name' => 'attribute_17_name',
'Attribute 17 value(s)' => 'attribute_17_value(s)',
'Attribute 17 visible' => 'attribute_17_visible',
'Attribute 17 global' => 'attribute_17_global',
'Attribute 18 name' => 'attribute_18_name',
'Attribute 18 value(s)' => 'attribute_18_value(s)',
'Attribute 18 visible' => 'attribute_18_visible',
'Attribute 18 global' => 'attribute_18_global',
'Attribute 19 name' => 'attribute_19_name',
'Attribute 19 value(s)' => 'attribute_19_value(s)',
'Attribute 19 visible' => 'attribute_19_visible',
'Attribute 19 global' => 'attribute_19_global',
'Attribute 20 name' => 'attribute_20_name',
'Attribute 20 value(s)' => 'attribute_20_value(s)',
'Attribute 20 visible' => 'attribute_20_visible',
'Attribute 20 global' => 'attribute_20_global',
'Attribute 21 name' => 'attribute_21_name',
'Attribute 21 value(s)' => 'attribute_21_value(s)',
'Attribute 21 visible' => 'attribute_21_visible',
'Attribute 21 global' => 'attribute_21_global',
'Attribute 22 name' => 'attribute_22_name',
'Attribute 22 value(s)' => 'attribute_22_value(s)',
'Attribute 22 visible' => 'attribute_22_visible',
'Attribute 22 global' => 'attribute_22_global',
'Attribute 23 name' => 'attribute_23_name',
'Attribute 23 value(s)' => 'attribute_23_value(s)',
'Attribute 23 visible' => 'attribute_23_visible',
'Attribute 23 global' => 'attribute_23_global',
'Attribute 24 name' => 'attribute_24_name',
'Attribute 24 value(s)' => 'attribute_24_value(s)',
'Attribute 24 visible' => 'attribute_24_visible',
'Attribute 24 global' => 'attribute_24_global',
'Attribute 25 name' => 'attribute_25_name',
'Attribute 25 value(s)' => 'attribute_25_value(s)',
'Attribute 25 visible' => 'attribute_25_visible',
'Attribute 25 global' => 'attribute_25_global',
'Attribute 26 name' => 'attribute_26_name',
'Attribute 26 value(s)' => 'attribute_26_value(s)',
'Attribute 26 visible' => 'attribute_26_visible',
'Attribute 26 global' => 'attribute_26_global',
'Attribute 27 name' => 'attribute_27_name',
'Attribute 27 value(s)' => 'attribute_27_value(s)',
'Attribute 27 visible' => 'attribute_27_visible',
'Attribute 27 global' => 'attribute_27_global',
'Attribute 28 name' => 'attribute_28_name',
'Attribute 28 value(s)' => 'attribute_28_value(s)',
'Attribute 28 visible' => 'attribute_28_visible',
'Attribute 28 global' => 'attribute_28_global',
);
$importer = new WC_Product_CSV_Importer( $csv_file_path, array(
'start_pos' => 0, // File pointer start.
'end_pos' => -1, // File pointer end.
'update_existing' => false, // Actualizar productos existentes
'mapping' => $mapping,
'verbose' => true, // Activa el modo detallado
'parse' => true, // Whether to sanitize and format data.
'delimiter' => ',', // CSV delimiter.
'prevent_timeouts' => false, // Check memory and time usage and abort if reaching limit.
//'enclosure' => '"', // The character used to wrap text in the CSV.
'escape' => "",
));
Cuando use ‘Atributo 1 Nombre’ => ‘Atribute_1_name’, funciona, pero los atributos no crean, cuando se usan ‘Atributo 1 Nombre’ => ‘Atributos: Name1’, los productos se importan pero no se muestran en la pantalla de productos.
Por cierto, cuando uso la pantalla del importador en los productos (importador de WooCommerce predeterminado) todo funciona bien, el problema es solo cuando intento hacerlo con código personalizado.
¡Se agradecen cualquier idea o consejo!