Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Add more than 1 free product with a coupon
- This topic has 17 replies, 2 voices, and was last updated 3 years, 9 months ago by Jane Christensen.
-
AuthorPosts
-
November 19, 2020 at 4:31 pm #16811Jane ChristensenParticipant
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!
November 19, 2020 at 5:03 pm #16812Soft79KeymasterYou 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)
November 19, 2020 at 5:11 pm #16813Jane ChristensenParticipantI 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;
} );November 19, 2020 at 5:16 pm #16814Soft79KeymasterI 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 );
November 19, 2020 at 5:20 pm #16815Jane ChristensenParticipantit does not :/ I am using a flatsome theme, not the child theme of that theme anymore, could that be why?
November 19, 2020 at 5:29 pm #16816Soft79KeymasterYes, 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!November 19, 2020 at 5:35 pm #16817Jane ChristensenParticipantI have never made my own plugin before, is there a forum/link you can send me for the steps?
November 19, 2020 at 5:39 pm #16818Soft79KeymasterActually 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.
November 19, 2020 at 5:41 pm #16819Jane ChristensenParticipantI dont know how to “create a directory” 🙁 I am working on a mac just FYI
November 19, 2020 at 5:51 pm #16822Soft79KeymasterI’ve sent you a custom plugin using wetransfer to car..@omni……com
November 19, 2020 at 5:55 pm #16823Jane ChristensenParticipantI got it! I will install it and let you know! Thank you! Is this a workout with any code? creating a new plugin?
November 19, 2020 at 5:56 pm #16824Jane ChristensenParticipantI 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?
November 19, 2020 at 5:59 pm #16826Jane ChristensenParticipantit worked! thank you so much!
November 19, 2020 at 5:59 pm #16827Soft79KeymasterYou can edit this plugin, adding rules whenever you want. No need to create multiple plugins for that.
November 19, 2020 at 6:00 pm #16828Soft79KeymasterGreat! Happy sales!
-
AuthorPosts
- You must be logged in to reply to this topic.