Code Snippets

Smart Coupons provide a powerful, “all-in-one” solution for gift certificates, store credits, discount coupons, and vouchers.

The below code snippets help you customize and tailor Smart Coupons according to your needs. You can try formatting the coupon code to generate only numerical values and avoid certain characters. You can also try small tweaks to the “Send coupons to…” form on the checkout page, and much more.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and are resolving potential conflicts, you may need to hire a developer for assistance.

Here are some code snippets listed to make your task easier with the Smart Coupons plugin. To safely add code snippets, you can follow the blog here.

1. Exclude characters from Auto generated coupon codes / Gift Cards / Gift Certificates

↑ Back to top

There would be instances where users would not be able to apply the coupon code properly due to distinguishing certain alphabets and numbers. Using the following code snippet, you can remove certain alphabets and numbers that could be avoided when auto generating coupons using the Smart Coupons plugin. Insert the following code snippet into your store to exclude characters such as ‘i’, ‘I’, ‘l’, ‘L’, ‘o’, ‘O’, ‘0’, 0.

2. Auto generate codes / Gift Cards / Gift Certificates with only numericals

↑ Back to top

If you are looking for auto generating coupons with only numericals and avoiding alphabets, then the following code snippet allows you to auto generate only numbers on the coupon code that gets generated.

3. Hide “Send to me” from the “Send Coupon to…” form on the checkout page

↑ Back to top

When customers purchase a gift card or any product that gives a coupon for the next purchase, they will receive options to send the coupon to themself or to someone else. The following code snippet allows to hide the “Send to me” option from the “Send Coupons to…” form on the checkout page.

4. Modify the purchase limit of the Gift Card

↑ Back to top

When selling gift cards/gift vouchers through the WooCommerce store using the Smart Coupons plugin, Gift card of any amount could have a maximum limit cap set so that gift cards cannot be purchased more than this limit. This code helps you set a maximum purchase limit for a gift card of any amount.

To set a minimum purchase limit, you can replace the line $input['max'] = '2000'; with $input['min'] = '10';

5. Modify the URL of the coupons received by email

↑ Back to top

After the purchase of a Gift card/Gift voucher, a coupon code is generated and sent to the email so that a user can click on it and be directed to your WooCommerce store. By default, this takes the user to the shop page, but if you would like to direct them to one of your custom pages, such as a product page, then this code will help you modify the URL of the coupon that you have received in your email.

6. Remove the store credit balance from the order email

↑ Back to top

If a store credit or gift voucher is used in an order and there is a remaining balance on that voucher, it will be shown as a balance on the order email. This code will help you remove the store credit balance from the order email.