Repository Forums Support WooCommerce Extended Coupon Features PRO Minimum value before coupon work without affecting number of free products

Topic Resolution: Resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4030
    joseph
    Participant

    Hi,

    I’m trying to get a coupon that gives a free product B for each product A bought, but only when 5 or more of A are in the basket. I’d be happy doing this with a minimum spend limit, however, the ‘minimum spend’ in the ‘usage restriction’ area also affects the number of product B you get (i.e. only 1 per 5). Am I missing something simple, or is there not a way to achieve this?

    Many thanks,

    Joseph

    #4034
    Soft79
    Keymaster

    This requires a small snippet in your child theme’s functions.php to work:

    
    add_filter( 'wjecf_free_product_amount_for_coupon',
      function( $coupon_qty, $coupon ) {
        if ( strcmp( $coupon->get_code(), 'COUPON_CODE' ) === 0 ) { 
          $min_matching_product_qty = intval( $coupon->get_meta( '_wjecf_min_matching_product_qty' ) );
          if ( $min_matching_product_qty > 0 ) {
            $coupon_qty = WJECF_API()->get_quantity_of_matching_products( $coupon ); 
            if ( $coupon_qty < $min_matching_product_qty ) {
              $coupon_qty = 0;
            }
          }
        }
        return $coupon_qty;
      }, 10, 2
    );
    

    Replace ‘COUPON_CODE’ by the actual coupon code. For the coupon set the minimum quantity of matching products to 5, and it will work.

    #4038
    joseph
    Participant

    Many thanks – works perfectly!

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