1
我使用WooCommerce和捆綁產品插件來顯示一個頁面,用戶可以在其中選擇配置產品的選項。每個選項都是具有變化的產品。爲了從所有4種產品中獲得變體,我使用下面的代碼。在我升級到WC 3(oops)之前,它曾經工作得很好。現在我得到一個錯誤,sku是空的。我是否需要改變從產品中獲得SKU的方式?Woocommerce - 從捆綁產品中獲取變體SKU
do_action('woocommerce_before_bundled_items', $product);
foreach ($bundled_items as $bundled_item) {
/**
* 'woocommerce_bundled_item_details' hook
*
* @hooked wc_pb_template_bundled_item_details_wrapper_open - 0
* @hooked wc_pb_template_bundled_item_thumbnail - 5
* @hooked wc_pb_template_bundled_item_details_open - 10
* @hooked wc_pb_template_bundled_item_title - 15
* @hooked wc_pb_template_bundled_item_description - 20
* @hooked wc_pb_template_bundled_item_product_details - 25
* @hooked wc_pb_template_bundled_item_details_close - 30
* @hooked wc_pb_template_bundled_item_details_wrapper_close - 100
*/
do_action('woocommerce_bundled_item_details', $bundled_item, $product);
$variations = $bundled_item->get_product_variations();
foreach($variations as $variation) {
if($variation['sku'] == 'colors') {
$bi['colors'] = $bundled_item;
continue 2;
}
if($variation['sku'] == 'material') {
$bi['material'] = $bundled_item;
continue 2;
}
if($variation['sku'] == 'corners') {
$bi['corners'] = $bundled_item;
continue 2;
}
if($variation['sku'] == 'text') {
$bi['text'] = $bundled_item;
continue 2;
}
}
do_action('woocommerce_after_bundled_items', $product);
}