Reputation: 107
My customer have products on the page that you can buy 12 and 12.
So the base value of the quantity field is 12, if you want to add another box you click the arrow and it will ad 12 so the quantity value changes from 12 to 24.
It's based on categories so if category == '12', the input base value is 12.
add_filter("woocommerce_quantity_input_args", function($args, $product){
if(has_term("12", "product_cat", $product->get_id())) {
$args['input_value'] = 12;
$args['min_value'] = 12;
$args['step'] = 12;
}
return $args;
}, 10, 2);
How do i fix so the quantity value follows to the checkout page, if i add 12x2 (24) to my cart it will only display 12 and not the same quantity value as the shop page (24)
Upvotes: 1
Views: 473
Reputation: 29624
You can use the woocommerce_checkout_cart_item_quantity
filter hook
So you get:
function filter_woocommerce_checkout_cart_item_quantity( $item_qty, $cart_item, $cart_item_key ) {
// Get product id
$product_id = $cart_item['product_id'];
// Has term
if ( has_term( 12, 'product_cat', $product_id ) ) {
// Output
$item_qty = '<strong class="product-quantity">' . sprintf( '× %s', 12 ) . '</strong>';
}
// Return
return $item_qty;
}
add_filter( 'woocommerce_checkout_cart_item_quantity', 'filter_woocommerce_checkout_cart_item_quantity', 10, 3 );
Upvotes: 2