Repository Forums Support WooCommerce Extended Coupon Features PRO Add more than 1 free product with a coupon

Topic Resolution: Resolved
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #16811
    Jane Christensen
    Participant

    Hello!

    I am getting ready to set up a coupon where if they purchase at least $100 they get 6 free hand sanitizers. Is there a way to set how many of the same product they get for free?

    Thanks!

    #16812
    Soft79
    Keymaster

    You can paste the following snippet in your child theme’s functions.php. Replace THE_COUPON_CODE with the actual coupon code.

    
    add_filter( 'wjecf_free_product_amount_for_coupon', function ( $coupon_qty, $coupon ) { 
      if ( strcasecmp( $coupon->get_code(), 'THE_COUPON_CODE' ) === 0 ) {
        $coupon_qty = 6;
      }
      return $coupon_qty;
    } );
    

    (Untested)

    #16813
    Jane Christensen
    Participant

    I put it in my child theme but it didn’t work, it is still showing just 1 at checkout 🙁

    add_filter( ‘wjecf_free_product_amount_for_coupon’, function ( $coupon_qty, $coupon ) {
    if ( strcasecmp( $coupon->get_code(), ‘clean’ ) === 0 ) {
    $coupon_qty = 6;
    }
    return $coupon_qty;
    } );

    #16814
    Soft79
    Keymaster

    I missed a 10, 2

    Does the following work?

    
    add_filter( 'wjecf_free_product_amount_for_coupon', function ( $coupon_qty, $coupon ) { 
      if ( strcasecmp( $coupon->get_code(), 'THE_COUPON_CODE' ) === 0 ) {
        $coupon_qty = 6;
      }
      return $coupon_qty;
    }, 10, 2 );
    
    #16815
    Jane Christensen
    Participant

    it does not :/ I am using a flatsome theme, not the child theme of that theme anymore, could that be why?

    #16816
    Soft79
    Keymaster

    Yes, that’s the cause. You could put it in the flatsome functions.php, but it will be overwritten when you update your theme. Alternatively you can create a custom plugin for this:

    1. On your PC create a directory jane-custom-plugin/
    2. In that directory create a file jane-custom-plugin.php with the following content:

    /*
    Plugin Name: Jane Custom Plugin
    Description: Custom Coupon functionality.
    Author: Jane Christensen
    Version: 1.0.0
    */
    
    add_filter( 'wjecf_free_product_amount_for_coupon', function ( $coupon_qty, $coupon ) { 
      if ( strcasecmp( $coupon->get_code(), 'THE_COUPON_CODE' ) === 0 ) {
        $coupon_qty = 6;
      }
      return $coupon_qty;
    }, 10, 2 );

    3. Zip the directory into a file jane-custom-plugin.zip (so the php-file is named jane-custom-plugin/jane-custom-plugin.php inside the zip-file)
    4. Go to wp-admin > Plugins > Add Plugin and upload and activate your plugin!

    #16817
    Jane Christensen
    Participant

    I have never made my own plugin before, is there a forum/link you can send me for the steps?

    #16818
    Soft79
    Keymaster

    Actually those 4 steps is all you need! Is there anything you’re stuck with?

    More info: https://developer.wordpress.org/plugins/ but this is probably too much information.

    #16819
    Jane Christensen
    Participant

    I dont know how to “create a directory” 🙁 I am working on a mac just FYI

    #16822
    Soft79
    Keymaster

    I’ve sent you a custom plugin using wetransfer to car..@omni……com

    #16823
    Jane Christensen
    Participant

    I got it! I will install it and let you know! Thank you! Is this a workout with any code? creating a new plugin?

    #16824
    Jane Christensen
    Participant

    I got it! I will install it and let you know! Thank you! Is this a work around with any code? creating a new plugin and installing it?

    #16826
    Jane Christensen
    Participant

    it worked! thank you so much!

    #16827
    Soft79
    Keymaster

    You can edit this plugin, adding rules whenever you want. No need to create multiple plugins for that.

    #16828
    Soft79
    Keymaster

    Great! Happy sales!

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