We’ve written a handful of guides on changing the coupon code wording to specific text. This is because some users find editing code snippets not particularly intuitive, especially non-coders. Do let us know if you need a guide on changing the coupon code text to something different and we’ll keep you in the loop. This particular guide shows you how you can replace the coupon code text with Promo Code. If you’re running a promotion as such, you may wish to change the coupon code text in WooCommerce to promo code for a better User Experience (UX).
/**
* Snippet Name: Rename Coupon Code to Promo 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 = 'Promo Code:';
}
if ('Coupon has been removed.' === $text){
$translated_text = 'Promo code has been removed.';
}
if ( 'Apply coupon' === $text ) {
$translated_text = 'Apply Code';
}
if ( 'Coupon code' === $text ) {
$translated_text = 'Promo Code';
}
return $translated_text;
}
function ecommercehints_rename_coupon_message_on_checkout() {
return 'Have a promo code? Enter it here';
}
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","Promo ",$err);
return $err;
}