• Resolved koullis

    (@koullis)


    hello

    is it possible to create a coupon and applied only if the customer bought another specific item?

    customer buys item 1. Same customer buys item 2, coupon applied to cart.
    customer buys item 2. Same customer buys item 3, no coupon
    customer buys item 2. no coupon
    customer buys item 1. Same customer buys item 3, coupon applied to cart.

    thank you for any help/replies

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Soft79

    (@josk79)

    I have a snippet somewhere that returns the percent cart discount which was removed from WC in v3.0. I’ll look it up and let you know.

    Thread Starter koullis

    (@koullis)

    ok would be nice to have this rather than sending out emails with the same code for customers who buy the specific item and get a discount on the upsell

    Plugin Author Soft79

    (@josk79)

    This snippet creates the ‘Percent cart discount’ coupon type:

    
    add_filter( 'woocommerce_cart_coupon_types', function ( $coupon_types ) {
     if ( ! in_array( 'percent_cart', $coupon_types ) ) $coupon_types[] = 'percent_cart';
     return $coupon_types;
    }, 10, 1 );
    
    add_filter( 'woocommerce_coupon_discount_types', function ( $coupon_discount_types ) {
     $coupon_discount_types['percent_cart'] = __( 'Percentage cart discount', 'your-language-domain' );
     $coupon_discount_types['percent'] = __( 'Percentage product discount', 'your-language-domain' );
     return $coupon_discount_types;
    }, 10, 1 );
    
    add_filter( 'woocommerce_coupon_get_discount_amount', function( $discount_amount, $discounting_amount, $cart_item, $single, $coupon ) {
     if ( $coupon->is_type( 'percent_cart' ) ) {
     $discount = (float) $coupon->get_amount() * ( $discounting_amount / 100.0 );
     $discount_amount = round( min( $discount, $discounting_amount ), wc_get_rounding_precision() );
     }
     return $discount_amount;
    }, 10, 5 );
    
    Thread Starter koullis

    (@koullis)

    does this do what i want? i would prefer to add specific amount rather than %

    where should i add the code?

    thank you

    • This reply was modified 6 years, 2 months ago by koullis.
    Plugin Author Soft79

    (@josk79)

    Then you don’t need the code at all and can just create a ‘Fixed cart discount’-coupon.

    Thread Starter koullis

    (@koullis)

    thank you for your reply.

    it seems that you didnt understand what i am looking for

    a fixed discount amount to any product B,C,D,E etc IF the customer ALSO bought product A otherwise no discount

    Plugin Author Soft79

    (@josk79)

    Aha! In the opening post you mentioned ‘coupon applied to cart’; but you need it applied to products….

    What you want is not possible out-of-the-box, it requires a bit of customization. Contact us at soft79.nl if you want us to do custom work.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘coupon for specific product’ is closed to new replies.