woocommerce_get_item_data我正在嘗試使用掛鉤在購物車中顯示非變體產品的一些自定義資料。即使我設定了條件,我仍然遇到變體產品的問題,給我一個錯誤。
我的代碼:
add_filter( 'woocommerce_get_item_data', 'display_cart_item_custom_meta_data', 10, 2 );
function display_cart_item_custom_meta_data( $item_data, $cart_item ) {
if ( empty($cart_item["variation"])) {
$my_data = $cart_item["my_data"];
$data_array = array();
$data_array[] = array(
'key' => "Some Key",
'value' => "Some Value",
);
return $data_array;
}
}
變體錯誤:
Warning: Invalid argument supplied for foreach() in /data/0/b/0b142c6f-d1fc-41f2-b82d-95dd95505032/xxx.sk/sub/shop/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 3741
Warning: count(): Parameter must be an array or an object that implements Countable in /data/0/b/0b142c6f-d1fc-41f2-b82d-95dd95505032/xxx.sk/sub/shop/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 3752
請問哪里有問題?
uj5u.com熱心網友回復:
add_filter('woocommerce_get_item_data', 'display_cart_item_custom_meta_data', 10, 2);
function display_cart_item_custom_meta_data($item_data, $cart_item) {
if (empty($cart_item["variation"])) {
$my_data = $cart_item["my_data"];
$data_array = array();
$data_array[] = array(
'key' => "Some Key",
'value' => "Some Value",
);
return $data_array;
}
return $item_data;
}
您應該始終回傳資料,否則會拋出錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/533651.html
標籤:PHPWordPress的woocommerce钩woocommerce产品变化
下一篇:WordPress代碼的干擾
