Comments Ale started the conversation3 weeks ago on December 29, 2024 at 11:07pmI sell t-shirts. The discount is not applied if I select different sizes. Example: I buy 10 t-shirts of size L and the discount is applied correctly, but if I buy 5 t-shirts of size L and 5 M, the discount is not applied. 1,287Dustin replied3 weeks ago on December 31, 2025 at 6:47amHi Ale, Please add the custom code below. (How to add custom code? ↗): add_filter( 'wpcpq_cart_item_quantity', function ( $quantity, $cart_item, $cart_item_key ) { if ( $cart_item['data']->is_type( 'variation' ) ) { $parent_id = $cart_item['data']->get_parent_id(); $quantity = 0; foreach ( WC()->cart->get_cart() as $c_item ) { if ( $c_item['data']->get_parent_id() == $parent_id ) { $quantity += $c_item['quantity']; } } } return $quantity; }, 99, 3 ); Then, it will count all variations of a variable product and give a correct discount.Best regards,Dustin Sign in to reply ...
I sell t-shirts. The discount is not applied if I select different sizes. Example: I buy 10 t-shirts of size L and the discount is applied correctly, but if I buy 5 t-shirts of size L and 5 M, the discount is not applied.
Hi Ale,
Please add the custom code below. (How to add custom code? ↗):
add_filter( 'wpcpq_cart_item_quantity', function ( $quantity, $cart_item, $cart_item_key ) { if ( $cart_item['data']->is_type( 'variation' ) ) { $parent_id = $cart_item['data']->get_parent_id(); $quantity = 0; foreach ( WC()->cart->get_cart() as $c_item ) { if ( $c_item['data']->get_parent_id() == $parent_id ) { $quantity += $c_item['quantity']; } } } return $quantity; }, 99, 3 );
Then, it will count all variations of a variable product and give a correct discount.
Best regards,
Dustin