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’.
9 comments
Keith S
This has no effect, has something changed in woocommerce to prevent this from working anymore?
mario
Raciel D
Works perfectly!! thanks!!
Wilbert Schaapman
What if you have two langugaes on your site, how to change the text using this fucntion for my two languages?
Bendert
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’ ) . ”;
}
david
Hi,
the Link to enter the coupon code doesn’t work.
Yury_au
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’ ) . ”;
}
Paul
Still doesn’t work.
Bavo
Hi Paul,
Have you been able to fix this? I have the same problem.
Raciel D
Try this:
add_filter( ‘woocommerce_checkout_coupon_message’, ‘bt_rename_coupon_message_on_checkout’ );
function bt_rename_coupon_message_on_checkout() {
return ‘‘ . __( ‘Have a voucher? Click here to enter your code’, ‘woocommerce’ ) . ‘‘;
}