Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3791523
Quantity discount does not apply
Open

Comments

  • Ale started the conversation

    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.

  •  1,287
    Dustin replied

    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