I've purchased the licence since I was under the impression I could offer a different price if a custumer wanted to buy different magnets (same item, different variations).
I have activated it, and I've found some code you've given to an other member that solved my issue.
I have an other one now : I have 2 différents products with variations, they are in the same category. If they order 2 (one of each product in the same category), I want the discount to apply.
I'm not a developper, but as I understand your code, I'll have the same pricing for all the catagories of your script.
I'd like different pricing in different catagories. If people buy 5 badges, they pay 5€ each instead of 7 (it work now), and if they buy 2 T-shirt, they pay 20, instead of 25.
Hello,
I'm selling t-shirts and badges on my website.
I've purchased the licence since I was under the impression I could offer a different price if a custumer wanted to buy different magnets (same item, different variations).
But I can't make it work, can you help me ?
Hi Valentin,
Please ensure that you have installed and activated the premium version.
For a variable product, click on the variation to configure the pricing:
Best regards,
Dustin
I have activated it, and I've found some code you've given to an other member that solved my issue.
I have an other one now : I have 2 différents products with variations, they are in the same category. If they order 2 (one of each product in the same category), I want the discount to apply.
It does not work...yet.
Thank you for your answer
Attached files: Capture d’écran 2025-01-30 à 11.17.35.png
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' ) ) { $pid = $cart_item['data']->get_parent_id(); } else { $pid = $cart_item['data']->get_id(); } if ( has_term( 'badges', 'product_cat', $pid ) ) { $quantity = 0; foreach ( WC()->cart->get_cart() as $c_item ) { if ( $c_item['data']->is_type( 'variation' ) ) { $cid = $c_item['data']->get_parent_id(); } else { $cid = $c_item['data']->get_id(); } if ( has_term( 'badges', 'product_cat', $cid ) ) { $quantity += $c_item['quantity']; } } } return $quantity; }, 99, 3 );Let me know if it works as you expected.
Best regards,
Dustin
Awesome it work.
Can you explain to me how I can do that with other product category, like "tshirt" for example ?
If you want to make it work with another plugin, please use the snippet like this:
add_filter( 'wpcpq_cart_item_quantity', function ( $quantity, $cart_item, $cart_item_key ) { if ( $cart_item['data']->is_type( 'variation' ) ) { $pid = $cart_item['data']->get_parent_id(); } else { $pid = $cart_item['data']->get_id(); } // this code is for badges category if ( has_term( 'badges', 'product_cat', $pid ) ) { $quantity = 0; foreach ( WC()->cart->get_cart() as $c_item ) { if ( $c_item['data']->is_type( 'variation' ) ) { $cid = $c_item['data']->get_parent_id(); } else { $cid = $c_item['data']->get_id(); } if ( has_term( 'badges', 'product_cat', $cid ) ) { $quantity += $c_item['quantity']; } } } // this code is for tshirt category if ( has_term( 'tshirt', 'product_cat', $pid ) ) { $quantity = 0; foreach ( WC()->cart->get_cart() as $c_item ) { if ( $c_item['data']->is_type( 'variation' ) ) { $cid = $c_item['data']->get_parent_id(); } else { $cid = $c_item['data']->get_id(); } if ( has_term( 'tshirt', 'product_cat', $cid ) ) { $quantity += $c_item['quantity']; } } } // this code is for another category if ( has_term( 'another', 'product_cat', $pid ) ) { $quantity = 0; foreach ( WC()->cart->get_cart() as $c_item ) { if ( $c_item['data']->is_type( 'variation' ) ) { $cid = $c_item['data']->get_parent_id(); } else { $cid = $c_item['data']->get_id(); } if ( has_term( 'another', 'product_cat', $cid ) ) { $quantity += $c_item['quantity']; } } } return $quantity; }, 99, 3 );Best regards,
Dustin
I'm not a developper, but as I understand your code, I'll have the same pricing for all the catagories of your script.
I'd like different pricing in different catagories. If people buy 5 badges, they pay 5€ each instead of 7 (it work now), and if they buy 2 T-shirt, they pay 20, instead of 25.