-
-
Save maxrice/8551024 to your computer and use it in GitHub Desktop.
| <?php | |
| // rename the "Have a Coupon?" message on the checkout page | |
| function woocommerce_rename_coupon_message_on_checkout() { | |
| return 'Have a Promo Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>'; | |
| } | |
| add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' ); | |
| // rename the coupon field on the checkout page | |
| function woocommerce_rename_coupon_field_on_checkout( $translated_text, $text, $text_domain ) { | |
| // bail if not modifying frontend woocommerce text | |
| if ( is_admin() || 'woocommerce' !== $text_domain ) { | |
| return $translated_text; | |
| } | |
| if ( 'Coupon code' === $text ) { | |
| $translated_text = 'Promo Code'; | |
| } elseif ( 'Apply Coupon' === $text ) { | |
| $translated_text = 'Apply Promo Code'; | |
| } | |
| return $translated_text; | |
| } | |
| add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_checkout', 10, 3 ); |
Actually I've tweaked it to the following code now, just to catch a couple more edge cases:
/**
* Soka - Change 'coupon' text to 'voucher'
* @source https://gist.github.com/maxrice/8551024
*/
function soka_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 = 'Redeem voucher';
}
if ( 'Coupon code' === $text ) {
$translated_text = 'Voucher code';
}
if ( 'If you have a coupon code, please apply it below.' === $text ) {
$translated_text = 'If you have a voucher code, please apply it below.';
}
return $translated_text;
}
add_filter( 'gettext', 'soka_rename_coupon_field_on_cart', 10, 3 );
/**
* Soka - Change 'coupon' text to 'voucher'
* @source https://gist.github.com/maxrice/8551024
*/
function soka_rename_coupon_message_on_checkout() {
return 'Have a voucher code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>.';
}
add_filter( 'woocommerce_checkout_coupon_message', 'soka_rename_coupon_message_on_checkout' );
/**
* Soka - Change 'coupon' text to 'voucher'
* @source https://gist.github.com/maxrice/8551024
*/
function soka_rename_coupon_label( $err, $err_code=null, $something=null ){
$err = str_replace("Coupon","Voucher",$err);
$err = str_replace("coupon","voucher",$err);
return $err;
}
add_filter( 'woocommerce_coupon_error', 'soka_rename_coupon_label', 10, 3 );
add_filter( 'woocommerce_coupon_message', 'soka_rename_coupon_label', 10, 3 );
add_filter( 'woocommerce_cart_totals_coupon_label', 'soka_rename_coupon_label',10, 1 );The code is not working for me, does anyone have an update?
add_filter( 'gettext', 'custom_translate_elementor_coupon_texts', 999, 3 );
function custom_translate_elementor_coupon_texts( $translated, $text, $domain ) {
if ( $domain === 'elementor-pro' ) {
switch ( $text ) {
case 'Have a coupon?':
$translated = 'Imate kupon?';
break;
case 'Click here to enter your coupon code':
$translated = 'Kliknite ovde da unesete kod kupona';
break;
case 'If you have a coupon code, please apply it below.':
$translated = 'Unesite kod kupona ispod';
break;
case 'Coupon code':
$translated = 'Kod kupona';
break;
case 'Apply':
$translated = 'Primeni';
break;
}
}
return $translated;
}
So I need this code but I honestly don't know what it is. I need your help.
If you have a coupon code, please apply it below
Bella rejoindre la maison de

I just went through this and this code snippet is working for me:
Just posting it for easy reference for future developers, as it compiles others feedback in this thread, plus fixes missing bits of html in one of the comments.