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

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