Let’s have a look at how to change WooCommerce Coupon Text with a few simple steps. The term ‘coupon’ is often used in WooCommerce, but what if you prefer to use ‘discount’ or ‘promo’ instead? This tutorial by Web Squadron will show you how to change the coupon text in WooCommerce using Code Snippets. This method is not only simple but also requires no coding skills.
Why Use Code Snippets?
Code snippets are small blocks of reusable code that can be inserted into a larger codebase. They are beneficial for several reasons:
- They’re free to use.
- They eliminate the need for a child theme.
- They offer protection and rollback options in case of issues.
Install the Code Snippets Plugin
To change the coupon text in WooCommerce, you’ll first need to install the Code Snippets plugin. Here’s how:
- Log in to your WordPress dashboard.
- Navigate to ‘Plugins’ and click on ‘Add New’.
- In the search bar, type ‘Code Snippets’.
- Find the Code Snippets plugin and click ‘Install Now’.
- After installation, click ‘Activate’.
Change WooCommerce Coupon Text with Code Snippets
Once you’ve installed the Code Snippets plugin, you can use it to change the coupon text. Follow these steps:
- In your WordPress dashboard, navigate to ‘Snippets’.
- Click on ‘Add New’.
- Give your new snippet a title.
- Copy & Paste the code below into your new snippet.
/** * Snippet Name: Rename Coupon Code to Discount Code everywhere in WooCommerce. * Snippet Author: ecommercehints.com */ add_filter( 'gettext', 'ecommercehints_rename_coupon_field_on_cart', 10, 3 ); add_filter( 'woocommerce_coupon_error', 'ecommercehints_rename_coupon_label', 10, 3 ); add_filter( 'woocommerce_coupon_message', 'ecommercehints_rename_coupon_label', 10, 3 ); add_filter( 'woocommerce_cart_totals_coupon_label', 'ecommercehints_rename_coupon_label',10, 1 ); add_filter( 'woocommerce_checkout_coupon_message', 'ecommercehints_rename_coupon_message_on_checkout' ); add_filter( 'gettext', 'woocommerce_change_coupon_field_instruction_text' ); function ecommercehints_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) { if ( is_admin() || 'woocommerce' !== $text_domain ) { return $translated_text; } if ( 'Coupon:' === $text ) { $translated_text = 'Discount Code:'; } if ('Coupon has been removed.' === $text){ $translated_text = 'Discount code has been removed.'; } if ( 'Apply coupon' === $text ) { $translated_text = 'Apply Code'; } if ( 'Coupon code' === $text ) { $translated_text = 'Discount Code'; } return $translated_text; } function ecommercehints_rename_coupon_message_on_checkout() { return 'Have a discount code? <a href="#" class="showcoupon">Enter it here</a>'; } function woocommerce_change_coupon_field_instruction_text($translated) { $translated = str_ireplace('If you have a coupon code, please apply it below.', '', $translated); return $translated; } function ecommercehints_rename_coupon_label( $err, $err_code=null, $something=null ){ $err = str_ireplace("Coupon","Discount ",$err); return $err; }
Source: Code Snippets
- Customize the text as desired. For example, you can change ‘discount code’ to ‘promo code’.
- Click ‘Save Changes’.
View the Changes
After saving your changes, you can see them in action:
- Go to your WooCommerce cart.
- Notice the original text that says ‘apply coupon’.
- Refresh the page.
- The text should now display your customized text (e.g., ‘apply code’).
Conclusion
Changing the coupon text in WooCommerce is a simple process with the Code Snippets plugin. You can customize the text to better suit your brand’s voice and style. Feel free to experiment with different terms like ‘promo’ or ‘special offer’.