【发布时间】:2019-09-12 06:23:08
【问题描述】:
我为特定产品创建了一个函数。客户可以选择物体的颜色。如果客户选择“RED”,在单个产品页面中输入的数量会更改为 select dropdwon 10,20,30,40,50 ...
对于同一产品如果客户选择“绿色”则选择更改为 5、10、15、20、25 ...
在我的测试中,我在购物车中添加了红色选项和绿色选项。
现在我进入购物车页面,我的购物车中有 2 件产品......很好!
但我的数量我不知道根据颜色更改自定义选择的数量输入字段。 我想为红色显示 slect 10,20,30,40,50...,为绿色显示 5,10,15,20,25...。
我想使用我的自定义 $cart_item_data['color'] 作为更改数量,因为产品 ID 与 $cart_item_data 更改相同。
我试过了
function custom_quantity_input_default( $args, $product ) {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$color = $values['color'];
if ($color == 'red'){
$qte = '5';
}
}
$args['step'] = $qte;
return $args;
}
add_filter( 'woocommerce_quantity_input_args', 'custom_quantity_input_default', 10, 2 );
但不起作用,因为 args 返回两个产品中的最后一个数字
【问题讨论】:
标签: woocommerce