April 28, 2023

Change WooCommerce Coupon Text – No Coding Required with Code Snippets

Play Video

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:

  1. Log in to your WordPress dashboard.
  2. Navigate to ‘Plugins’ and click on ‘Add New’.
  3. In the search bar, type ‘Code Snippets’.
  4. Find the Code Snippets plugin and click ‘Install Now’.
  5. 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:

  1. In your WordPress dashboard, navigate to ‘Snippets’.
  2. Click on ‘Add New’.
  3. Give your new snippet a title.
  4. 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

  5. Customize the text as desired. For example, you can change ‘discount code’ to ‘promo code’.
  6. Click ‘Save Changes’.

View the Changes

After saving your changes, you can see them in action:

  1. Go to your WooCommerce cart.
  2. Notice the original text that says ‘apply coupon’.
  3. Refresh the page.
  4. 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’.


Required Resources

WooCommerce Logo
Free Options
Code Snippets Logo
Free Options
Credit to Web Squadron
Web Squadron is a popular YouTube channel dedicated to providing informative tutorials, tips, and insights on web development and design. With a strong focus on WordPress and website builders like Bricks Builder, the channel aims to help users of all skill levels, from beginners to advanced developers, create and optimize their websites. By offering easy-to-understand, step-by-step guidance, Web Squadron provides practical and valuable content.
Visit
Change WooCommerce Coupon Text – No Coding Required with Code Snippets
Welcome back!
Enter your Helwp credentials to sign in.

No Account yet? Sign Up

My Account
Menu
Give Feedback
Describe your feedback *
Rate Helwp
Share
Facebook
Twitter
LinkedIn
Reddit
Email
WhatsApp
Telegram
Pocket
Report
Problem *
Describe the problem
Want us to reply?
Your E-Mail
Affiliate Disclosure

At Helwp, we’re committed to transparency and honesty. Therefore, we want to inform you that some of the links on our website are affiliate links. This means that, at no additional cost to you, we may earn a small commission if you click through and make a purchase.

We only promote products or services that we genuinely believe in. These affiliate commissions help us to maintain the website and continue to provide you with free, high-quality WordPress content.

If you are interested in how you can support us even further, check out our support page.