Repository Forums Support WooCommerce Extended Coupon Features PRO Buy two, get a third for free-scenario

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2328
    Mono
    Participant

    Hi,
    I’m looking for how to achieve this scenario:

    Order at least one of A, B, C or/and D and get the option to get one free E for every two of E. So, if you order one A it gives you every third E for free.

    Any idea how to set this up?

    Thanks!

    #2332
    Soft79
    Keymaster

    Hi,

    this is possible with an additional little custom script in the functions.php of your child theme.

    1. Create a coupon with Discount type: Percent discount and a value of 100%
    2. On Usage Restrictions tab in Products (OR) select A, B, C and D.
    3. On Usage Restrictions tab set Min. quantity of matching products to: 3
    4. On Usage Limits tab choose Limit discount to: Every nth item
    5. Add the following script to functions.php of your child theme (replace 83 by the product-id of item ‘E’ and replace the-code-of-the-coupon by your coupon code.

    
    add_filter( 'woocommerce_coupon_is_valid_for_product', function( $valid, $product, $coupon, $values ) {
        $my_item_id = 83;
        $my_coupon_code = 'the-code-of-the-coupon';
    
        if ( $coupon->get_code() === $my_coupon_code ) {
            return $product->get_id() == $my_item_id;
        }
        return $valid;
    }, 10, 4 );
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.