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

Okay
  Public Ticket #3755394
Qty based pricing to apply to variable product as a whole (2 red, 2 blue, 2 green) = 6
Open

Comments

  •  2
    Trent started the conversation

    Hi.

    I am setting up WPC Price by Quantity 5.1.6 on a variable product.

    My quantity based pricing options are:
    6 - 90%
    12 - 80%

    I have a variable product with 5 variations (color).

    My expectation is: 2 x red, 2 x blue, 2 x green = 6 (i get the discount!)

    But the plugin doesn't work like this, it is isolating the count to each variation, so a discount will only apply if I buy 6 or more of a single variation.

    I want the quantity based discount to apply to the variable product as a whole.

    This in fact should be configurable, to choose how you want the count to operate per variable product or Pricing Table (as you call it).

    Do you have a solution to meet my needs?

  •  1,222
    Dustin replied

    Hi Trent,

    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 );

    Let me know if it works as you expected.

    Best regards,
    Dustin

  •  2
    Trent replied

    Hi Dustin.

    Works as expected now, thanks so much..!

    =)