我在PHP代码片段中使用woocommerce_quantity_input_args
钩子,我在元数据中 for each 产品保存了一个数字,我想将该元数据应用到购物车中的每个数量步骤的$args['step']
中,因为它们不都是相同的.
代码:
add_filter( 'woocommerce_quantity_input_args', 'woocommerceQuantityInputArgs', 10, 2);
function woocommerceQuantityInputArgs( $args, $product ) {
if ( ! is_cart() ) {
$cart = WC()->cart->get_cart();
foreach( $cart as $cart_item_key => $cart_item ){
$product = $cart_item['data'];
$args['step'] = $product->get_meta('_quantity_product_in_package');
}
}
}
我曾try 将所有元数据保存在单独的数组中,并循环遍历它,然后将其应用于$args,但不起作用