我尝试使用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
请问问题出在哪里?
1条答案
按热度按时间yvt65v4c1#
你应该总是返回数据,否则,它将抛出错误。