每次单击添加到购物车按钮时,我都想添加客户选择的产品数量的项目,
我尝试使用可变产品修改产品数量,woocommerce_add_to_cart_validation但它会将可变产品两次添加到购物车中:
function so_validate_add_cart_item( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) {
global $product;
$product = new WC_Product($product_id);
if(!$variation_id) {
WC()->cart->add_to_cart( $product_id, ($quantity *3) - $quantity );
} else {
WC()->cart->add_to_cart( $variation_id, ($quantity *3) );
}
// do your validation, if not met switch $passed to false
return $passed;
}
add_filter( 'woocommerce_add_to_cart_validation', 'so_validate_add_cart_item', 10, 5 );
白衣非少年