Repository Forums Support WooCommerce Extended Coupon Features PRO Adding right amount of free product

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #15363
    Katja Mosbach
    Participant

    Hi!

    Reposting:
    I’ve tried several different options. What I’m trying to set up this:
    Buy 12 matching products and get 1 for free.

    So it should be:
    12 same products in the cart -> adds 1 free product of the same product.
    No matter if you also have 1 or more of other products in the cart:

    12 Product A + 1 free Product A
    3 Product B – no free Product B

    OR

    12 Product A + 1 free Product A
    12 Product B + 1 free Product B
    3 Product C – no free Product C

    I cant make it work cause either it adds same amount och free products or it add free products on all or it removes the discount when you add another product to your cart of 12 products. Is there a code snippet that I must add or something because with the settings it constantly ends up being wrong solution.

    PLEASE HELP <3

    #15364
    Soft79
    Keymaster

    – Tick BOGO matching products
    – Tick Allow multiplication of the free products
    – Use this snippet:

    
    add_filter( 'wjecf_bogo_product_amount_for_coupon', function( $amount, $coupon ) {
      if ( strcasecmp( $coupon->get_code(), 'COUPON_CODE_HERE' ) === 0 ) {
        $amount = floor($amount / 12);
      }
      return $amount;
    }, 10, 2 );
    
    #15367
    Katja Mosbach
    Participant

    Thank you, thank you!!

    Just to be super sure:
    I’m adding the code snippet to functions of the theme that I use?
    Cause i tried some of the code snippets I found on the forums, but not sure if maybe then posted them in the wrong file? So just want to know the best file to post your code snippet!!

    Thank you again!

    #15368
    Soft79
    Keymaster

    In your child theme‘s functions.php

    #15371
    Katja Mosbach
    Participant

    Hi! Thank you once again!

    I’ve done as said – but it still adds 12 free products rather than just on 1 free/12.
    Also as soon you have 12 in the cart or more, for example 14 it adds 14 free products.
    And then also if you add another totally different product, just like 1, to the cart of the 14 then it counts the same in the cart – adding a 1 free product/1 product. So you end up with 14product + 14free + 1another product +1 free another product = 30 products in the cart in total.

    My settings are:
    General: Fixed product discount
    Usage Restrictions: Ticked: Cant combine with other discunts / Cant be applied on sale / Minimum quantity of matching products: 12
    Usage Limits: Limit discount to every nth item
    Free Products: Ticked: BOGO matching products / Allow multiplication of the free products
    Otherwise only ticked Auto coupon.

    Is that what effs it up? Or does the code snippet need adjustment?

    Please let me know <3

    #15372
    Soft79
    Keymaster

    In the code snippet you need to replace COUPON_CODE_HERE with the actual coupon code.

    #15373
    Katja Mosbach
    Participant

    Oh shit!

    I’m sorry. I did that and its almost perfect now!!
    Everything works as it should except that if I add more than 12, may it be 13, 14 or 20. It still adds 1 free product. Is it possible to constraint it only 12 products?
    I tried

    Usage Restrictions: Ticked: Cant combine with other discunts / Cant be applied on sale / Minimum quantity of matching products: 12 / Maximum quantity of matching products: 12

    and also the combination

    Usage Restrictions: Ticked: Cant combine with other discunts / Cant be applied on sale / Minimum quantity of matching products: 12
    Usage Limits: Limit usage to X items: 12 / Limit discount to every nth item

    Did not work. As said its almost perfect but needs to be restricted to 12 products only

    #15374
    Soft79
    Keymaster

    Remove the Max quantity of matching products.
    Don’t use limit discount to every nth item.
    Tick ‘allow multiplication’

    BTW; it should add zero products if you have it setup as you say and there are more than 12 items in the cart…

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