Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoStino/95769e7a64147ea68b4d4e9fe8ab9695 to your computer and use it in GitHub Desktop.
Save FrancoStino/95769e7a64147ea68b4d4e9fe8ab9695 to your computer and use it in GitHub Desktop.
Rename Coupon Code Text in WooCommerce
<?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