I was wondering if it was possible to make the coupon field mandatory on WooCommerce.
I know that this is possible using functions, however this is slightly above my current skill level so I was wondering if you could give me a step-by-step version of how to accomplish this. Any answer would be much appreciated.
I don’t know about the function but you can modify the plugin to achieve this in following manner :
Make one folder in your theme folder woocommerce and in new created woocommerce folder, create another folder with checkout name.
So now it will look something like wp-content > themes > your-theme > woocommerce > checkout.
Now go to your plugin directory and follow below path :
wp-content > plugins > woocommerce > templates > checkout
When you go in above path, you will find one file named as
form-coupon.php
. Copy that file and paste it to the directory which we created at top of that answer.wp-content > themes > your-theme > woocommerce > checkout > form-coupon.php
.Now its time to modify the code in wp-content > themes > your-theme > woocommerce > checkout > form-coupon.php :
Find following code line in above mentioned file :
And replace above line with
Note: Here I have added
required
attribute ofhtml
.Tell me if you have any doubt.
UPDATED:
Please give it a try and let me know feedback.
NOTE:
UNTESTED
to solve the problem try this code:
in functions.php instead of the one above…
for me it works
Add the following code in functions.php
Require Coupon for Single Product
Replace 37 by the your product ID in
$targeted_ids = array(37);
you can have multiple product IDs like$targeted_ids = array(37,48,12);
Replace “summer2” by any other coupon code in
$coupon_code = 'summer2';
Don’t forget to add this coupon code in WooCommerce before using it.
Require coupon for all products
Replace
$product_categories = array( 'clothing' );
by any other category name or category ID.