Repository Forums Support WooCommerce Extended Coupon Features PRO Buy Product A get 30% off each Product B

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #3027

    We have 2 collections of products – A and B.

    This is the coupon we need-
    If someone adds a Product A to their cart, all the Products B’s each get 30% off.

    This is what we have setup that’s not working-
    Discount type: Percentage Discount
    Discount amount: 30
    Coupon cannot be used with others.
    Products (OR): This is where we have all our Product B’s listed.
    Excluded products: This is where we have all Product A’s since we don’t want the coupon applied to those.

    At least one Product A has to be added to the cart for any Product B’s to receive the discount because it’s a BOGO type deal.

    Is this possible to set up?


    This requires a snippet in functions.php of your child theme.

    Change Products (OR) to Products (AND) and add this snippet:

    add_filter( 'woocommerce_coupon_is_valid_for_product', function( $valid, $product, $coupon, $values ) {
        $my_item_id = 123; // ID OF PRODUCT B
        $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 );

    Replace 123 with the id of product B and replace the-code-of-the-coupon with the actual coupon code.


    Added! It worked when we tested one product.

    We have 8 total product B’s and separating the item ids by commas didn’t work (got a syntax error).

    Is there something I could add to the snippet for multiple products?

    Thank you!


    That requires a more complicated customization. Use the contact form for inquiries.

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