Repository Forums Support WooCommerce Extended Coupon Features PRO Buy one item, receive 50% off another specific item

Topic Resolution: Resolved
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #16100
    andy3
    Participant

    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

    #16101
    andy3
    Participant

    Ok 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!

    #16102
    Soft79
    Keymaster

    That would require some customization. For example the snippet at https://www.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!

    #16107
    andy3
    Participant

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

    #16109
    andy3
    Participant

    Thank 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.

    #16111
    Soft79
    Keymaster

    Great!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.