Created
September 6, 2022 12:23
-
-
Save FrancoStino/95769e7a64147ea68b4d4e9fe8ab9695 to your computer and use it in GitHub Desktop.
Rename Coupon Code Text in WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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 = 'Codice promozionale:'; | |
} | |
if ('Coupon has been removed.' === $text){ | |
$translated_text = 'Il codice promozionale è stato rimosso.'; | |
} | |
if ( 'Apply coupon' === $text ) { | |
$translated_text = 'Applica'; | |
} | |
if ( 'Coupon code' === $text ) { | |
$translated_text = 'Inserisci codice promozionale'; | |
} | |
return $translated_text; | |
} | |
// Rename the "Have a Coupon?" message on the checkout page | |
function bt_rename_coupon_message_on_checkout() { | |
return 'Hai un codice promozionale?' . ' ' . __( 'Clicca per inserire il codice', 'woocommerce' ) . ''; | |
} | |
function bt_rename_coupon_label( $err, $err_code=null, $something=null ){ | |
$err = str_ireplace("Coupon","Codice promozionale ",$err); | |
return $err; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment