Changing the WooCommerce coupon text in cart and checkout pages

Want to change the WooCommerce coupon text… there are a few areas that need to be tackled namely the cart and the checkout pages, WooCommerce has most of the filters needed and the gettext filter can finish off translating the text string.

add_filter( 'gettext', 'bt_rename_coupon_field_on_cart', 10, 3 );
add_filter( 'woocommerce_coupon_error', 'bt_rename_coupon_label', 10, 3 );
add_filter( 'woocommerce_coupon_message', 'bt_rename_coupon_label', 10, 3 );
add_filter( 'woocommerce_cart_totals_coupon_label', 'bt_rename_coupon_label',10, 1 );
add_filter( 'woocommerce_checkout_coupon_message', 'bt_rename_coupon_message_on_checkout' );
/**
 * WooCommerce
 * Change Coupon Text
 * @param string $text
 * @return string
 * @link https://gist.github.com/maxrice/8551024
 */

function bt_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
	// bail if not modifying frontend woocommerce text
	if ( is_admin() || 'woocommerce' !== $text_domain ) {
		return $translated_text;
	}
	if ( 'Coupon:' === $text ) {
		$translated_text = 'Voucher Code:';
	}

	if ('Coupon has been removed.' === $text){
		$translated_text = 'Voucher code has been removed.';
	}

	if ( 'Apply coupon' === $text ) {
		$translated_text = 'Apply Voucher';
	}

	if ( 'Coupon code' === $text ) {
		$translated_text = 'Voucher Code';
	
	} 

	return $translated_text;
}


// Rename the "Have a Coupon?" message on the checkout page
function bt_rename_coupon_message_on_checkout() {
	return 'Have a coupon code?' . ' ' . __( 'Click here to enter your code', 'woocommerce' ) . '';
}


function bt_rename_coupon_label( $err, $err_code=null, $something=null ){
	$err = str_ireplace("Coupon","Voucher Code ",$err);
	return $err;
}

Add the above in functions.php the example changes ‘coupon’ for ‘voucher’.

 

ref

9 Comments

  1. Keith S on April 27, 2023 at 3:34 pm

    This has no effect, has something changed in woocommerce to prevent this from working anymore?

  2. mario on March 31, 2023 at 1:45 pm

    Raciel D
    Works perfectly!! thanks!!

  3. Wilbert Schaapman on September 29, 2021 at 6:36 am

    What if you have two langugaes on your site, how to change the text using this fucntion for my two languages?

  4. Bendert on October 27, 2020 at 5:08 pm

    Function bt_rename_coupon_message_on_checkout should be changed accordingly to fix link to enter the coupon code on the checkout page.

    function bt_rename_coupon_message_on_checkout() {
    return ‘Have a coupon or gift card code?’ . ‘ ‘ . __( ‘Click here to enter your code‘, ‘woocommerce’ ) . ”;
    }

  5. david on July 16, 2020 at 2:26 pm

    Hi,

    the Link to enter the coupon code doesn’t work.

    • Yury_au on May 17, 2022 at 12:44 am

      Hey David, change it to

      // Rename the “Have a Coupon?” message on the checkout page
      function bt_rename_coupon_message_on_checkout() {
      return ‘Have a coupon code?’ . ‘ ‘ . __( ‘Click here to enter your code‘, ‘woocommerce’ ) . ”;
      }

Leave all Comment