Cart, Checkout

WooCommerce Change Coupon Code To Discount Code

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

In some contexts, “coupon” is just the wrong word to use. For specifics, we have created a handful of guides on renaming coupon to the most popular synonyms. This guide in particular shows you how can you can change replace the word “coupon” with “discount”. Sadly, changing coupon code to discount code not as straight forward as it seems but we’ve written this useful code snippet which will replace the string everywhere the front-end user would see it including the cart and checkout.

/**
* 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;
}

Snippet Benefits

  • Tailor the default WooCommerce coupon strings to your business needs. You may have promotional material with the wording of “discount” and want ot follow this through on the website for consistency.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER