I'm working on an ecommerce website and I need your help. I was trying to modify the Text "Apply" in the Apply Coupon button in the Checkout page for a long time, and nothing achieved the goal. since I need to replace Apply Coupon with Arabic translation, I tried to use Loco Translate plugin and nothing has changed. And I tried to add this code into the functions file:
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
*/
function njengah_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 njengah_rename_coupon_message_on_checkout() {
return 'Have a coupon code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '';
}
function njengah_rename_coupon_label( $err, $err_code = null, $something = null ) {
$err = str_ireplace( 'Coupon', 'Voucher Code ', $err );
return $err;
}
is there any solution to this problem? it is the only English word in the whole