Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › add a product on the cart to get discount on other category
- This topic has 5 replies, 2 voices, and was last updated 4 years, 11 months ago by marianaferreira.
-
AuthorPosts
-
October 22, 2018 at 9:08 pm #3994marianaferreiraParticipant
Hello!
I wanted to make a coupon discount that gives 10% off on the category Shoes when the client buy our new Bag together, but i don’t want the discount to apply on the bag, just the shoes, is that possible? I tried to make it but i failed, the coupom apply to both of them, can you help me with it? Thanks!October 22, 2018 at 9:15 pm #3995marianaferreiraParticipantMy actual settings:
https://imgur.com/a/sfDFPvS
https://imgur.com/a/vX0nl4fOctober 23, 2018 at 7:19 am #3996Soft79Keymaster1) Create a coupon with these settings:
Discount type: Percent discount
Discount amount: 10
Products: Bag
Categories: Shoes2) Paste the following snippet in your child theme’s functions.php and replace COUPON_CODE and 123 with the actual coupon code and id of the Shoes-category (you can find the category id by looking at the url of the category’s edit page; look for something like &tag_ID=123 ):
add_filter( 'woocommerce_coupon_get_discount_amount', function( $discount, $discounting_amount, $cart_item, $single, $coupon ) { $COUPON_CODE = 'COUPON_CODE'; // replace with the coupon code $DISCOUNTED_CATEGORY = 123; // replace with the category that is discounted if ( 0 == strcasecmp( $coupon->code, $COUPON_CODE ) ) { $cat_ids = $cart_item['data']->get_category_ids(); if ( ! in_array( $DISCOUNTED_CATEGORY, $cat_ids ) ) { $discount = 0; } } return $discount; }, 10, 5 );
I haven’t tested the snippet, so let me know if it doesn’t work.
October 23, 2018 at 3:07 pm #3999marianaferreiraParticipantHello,
Thanks for the quick reply!
I replaced what you asked on the code but it haven’t worked yet.
That’s no discount applyed anymore on the shopping cartCategory Shoes: https://imgur.com/a/j61WGKr
Snipped: https://imgur.com/a/QpzD0np
Shopping cart with snipped active: https://imgur.com/a/guH1CRKShopping cart with snipped innactive: https://imgur.com/a/zByKH1z
Can you help me to fix it? Thanks in advance!
October 23, 2018 at 3:43 pm #4000Soft79KeymasterProbably because it’s a variable product. Try this:
add_filter( 'woocommerce_coupon_get_discount_amount', function( $discount, $discounting_amount, $cart_item, $single, $coupon ) { $COUPON_CODE = 'COUPON_CODE'; // replace with the coupon code $DISCOUNTED_CATEGORY = 123; // replace with the category that is discounted if ( 0 == strcasecmp( $coupon->code, $COUPON_CODE ) ) { $_product = $cart_item['data']; if ( $_product->get_parent_id() ) { $_product = wc_get_product( $_product->get_parent_id() ); } $cat_ids = $_product->get_category_ids(); if ( ! in_array( $DISCOUNTED_CATEGORY, $cat_ids ) ) { $discount = 0; } } return $discount; }, 10, 5 );
October 23, 2018 at 4:24 pm #4001marianaferreiraParticipantIt worked now! Thanks a lot for the excelent support 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.