У меня есть woocommerce (wordpress) в актуальном состоянии, с более чем 10 тысячами продуктов, для которых мне нужно создать варианты, есть четыре вида вариантов, два - на бумажном носителе с контролем запаса, два других варианта продукта не нужныуправление запасами.
Я проверил так много разных способов, которыми люди создавали программные варианты и пытались использовать свои сценарии на сайте разработчиков, и я начинаю замечать ошибки.
<?php
require_once('wp-load.php'); // load the wordpress core
require_once('functions.php') ; // custom functions to grab related data from the wpdb
$import_id = GetTheNextProduct(); // non-wordpress database
$is_variable_product = CheckIfVariable($import_id) ;
$post_id = GetRelatedWPDI($import_id); // returns related word press post `ID` of the product
// ... other variables are set in the same way... ie: $sku = GetSKU($import_id) ;
// the problem I am having is getting the current variation array into woocommerce variations,
// I've been able to do everything else.
if($is_variable_product == 1) {
$variations = GetVariations($import_id) ;
// woocommerce proper way to create variations....????
}
/* out example of $variations...
$variations = array(
"0" => array(
"ProductType" => "Small PDF",
"filepath" => "/path/to/pdf/file.pdf",
"filename" => "file.pdf",
"price" => "5.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "",
"_length" => "",
"_width" => "",
"_height" => "",
"_width" => "",
"inventory" => "unlimited",
"_sku" => "parent",
),
"1" => array(
"ProductType" => "Large PDF",
"filepath" => "/path/to/pdf/file-large.pdf",
"filename" => "file-large.pdf",
"price" => "10.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "",
"_length" => "",
"_width" => "",
"_height" => "",
"_width" => "",
"inventory" => "unlimited",
"_sku" => "parent",
),
"2" => array(
"ProductType" => "Small Hardcopy",
"filepath" => "",
"filename" => "",
"price" => "15.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "0.5",
"_length" => "",
"_width" => "8",
"_height" => "11",
"_width" => "",
"inventory" => "123",
"_sku" => "parent",
),
"4" => array(
"ProductType" => "Large Hardcopy",
"filepath" => "",
"filename" => "",
"price" => "20.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "0.5",
"_length" => "",
"_width" => "8",
"_height" => "11",
"_width" => "",
"inventory" => "456",
"_sku" => "parent",
),
)
*/
update_post_meta( $post_id, '_sku', $sku);
update_post_meta( $post_id,'_visibility','visible');
wp_set_object_terms($post_id, 'variable', 'product_type');
// do something here to the current $variations array variable to...
$variation_id = wp_insert_post( $variation_post );
$variation = new WC_Product_Variation( $variation_id );
foreach($variations as $vars_sub){
foreach($vars_sub as $key => $value) {
update_post_meta( $variation_id, 'attribute_'.$key, $value );
}
}
IЯ прочитал, перепробовал так много предложений сценариев в стеке, некоторые из которых очень помогли с простыми продуктами, которые остаются простыми ... но этот поставил меня в тупик.