Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Buy one item, receive 50% off another specific item
- This topic has 5 replies, 2 voices, and was last updated 6 years, 1 month ago by Soft79.
- AuthorPosts
- July 24, 2020 at 6:52 pm #16100andy3Participant
Hello All:
Love this plugin!
We have a sale that we would like to do.
Buy one of these particular SKUs of shoes, receive 50% off this one particular sandal. And we would like it to auto apply.
I tried adding the sandal as the only items it could apply on and use the “_sku” custom attribute and it doesn’t work.
I also just upgraded to version 3.2 and now the custom field has disappeared! So now my old coupons with the custom changes do not work correctly help!
Andy
July 24, 2020 at 6:58 pm #16101andy3ParticipantOk update – when I upgraded the plugin somehow deactivated and I needed to reactiveate it. Crisis averted! Phew.
I’d still love help with the first question though.
THanks!
July 25, 2020 at 9:13 am #16102Soft79KeymasterThat would require some customization. For example the snippet at http://soft79.nl/forums/topic/add-a-product-on-the-cart-to-get-discount-on-other-category/#post-4000 will only apply the discount to products from a certain category (e.g. set it to the category id of the Sandals) combine that with entering only the sandal and shoe SKU’s in the coupon usage restrictions fields and it might just work!
July 27, 2020 at 8:34 pm #16107andy3ParticipantThank you,
So would the snippet look like this? Or do I need to plugin the coupon code and category in the “if” portion of the snippet? Do I need to change the 10 and 5 in the last line at all?
add_filter( ‘woocommerce_coupon_get_discount_amount’, function( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
$COUPON_CODE = ‘louiseflash’; // replace with the coupon code
$DISCOUNTED_CATEGORY = 971 ; // replace with the category that is discountedif ( 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 );July 28, 2020 at 3:46 pm #16109andy3ParticipantThank you! I was able to get it to work. I had to make sure there were 2 matching products in the cart for it to work as expected.
July 28, 2020 at 4:08 pm #16111Soft79KeymasterGreat!
- AuthorPosts
- You must be logged in to reply to this topic.