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

2 Comments

  1. 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’ ) . ”;
    }

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

    Hi,

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

Leave a Comment