ResolvedChange coupon to discount – WooCommerce
Tagged: functions.php, woocommerce
- This topic has 2 replies, 2 voices, and was last updated 2 years, 10 months ago by
IainBeaumont.
- AuthorPosts
- November 3, 2020 at 9:31 am #26909
IainBeaumont
ParticipantDear Althemist,
I would like to change the word coupon to discount during the cart & checkout phase of WooCommerce. I have tried using the following code within the Child functions.php folder (which works on my other WooCommece sites) but to no effect.
add_filter( ‘gettext’, ‘woocommerce_rename_coupon_field_on_cart’, 10, 3 );
add_filter( ‘gettext’, ‘woocommerce_rename_coupon_field_on_cart’, 10, 3 );
add_filter(‘woocommerce_coupon_error’, ‘rename_coupon_label’, 10, 3);
add_filter(‘woocommerce_coupon_message’, ‘rename_coupon_label’, 10, 3);
add_filter(‘woocommerce_cart_totals_coupon_label’, ‘rename_coupon_label’,10, 1);
add_filter( ‘woocommerce_checkout_coupon_message’, ‘woocommerce_rename_coupon_message_on_checkout’ );function woocommerce_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 = ‘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;
}// rename the “Have a Coupon?” message on the checkout page
function woocommerce_rename_coupon_message_on_checkout() {
return ‘Have a Discount Code?’ . ‘ ‘ . __( ‘Click here to enter your code’, ‘woocommerce’ ) . ”;
}function rename_coupon_label($err, $err_code=null, $something=null){
$err = str_ireplace(“Coupon”,”Discount Code “,$err);
return $err;
}Please can you advise what I need to do in respect of the BabyStreet theme?
Kind regards
Iain
November 3, 2020 at 9:40 am #26912Althemist
KeymasterHello Iain,
I am afraid that’s not theme related. It’s part of the WooCommerce functionality, so we can’t really help with this.
However, if the only thing you want to do is changing the name of the coupon related fields, there is no need to write custom functions. Just use Loco translate and change the text string to whatever you want.
Regards,
DimitarNovember 3, 2020 at 9:57 am #26917IainBeaumont
ParticipantHi, thank you for your response.
I have found a temporary workaround (added to functions.php) until I can specify to WooCommerce
add_filter( ‘gettext’, ‘change_coupon_text’, 20, 3);
function change_coupon_text( $translated_text, $text, $text_domain){
$text = str_replace( “Coupon”, “Discount”, $text );
$text = str_replace( “coupon”, “Discount”, $text );
return $text;
} - AuthorPosts
You must be logged in and have valid license to reply to this topic.