1

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

mujuonly
  • 11,370
  • 5
  • 45
  • 75
Rama Absa
  • 99
  • 11
  • You're passing `bt_rename_coupon_field_on_cart` function in filter but your function name is `njengah_rename_coupon_field_on_cart`, your code is going to work, unless your pass the correct function names in filters – Vijay Hardaha Sep 21 '22 at 20:09

1 Answers1

0
add_filter('gettext_woocommerce', 'rename_coupon_text_on_cart', 10, 3);

function rename_coupon_text_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 = 'رمز الكوبون:';
    }

    if ('Coupon has been removed.' === $text) {
        $translated_text = 'تمت إزالة رمز القسيمة.';
    }

    if ('Have a coupon?' === $text) {
        $translated_text = 'هل لديك قسيمة؟';
    }
    if ('Click here to enter your code' === $text) {
        $translated_text = 'انقر هنا لإدخال الرمز الخاص بك';
    }


    if ('If you have a coupon code, please apply it below.' === $text) {
        $translated_text = 'إذا كان لديك رمز قسيمة ، يرجى تطبيقه أدناه.';
    }

    if ('Apply coupon' === $text) {
        $translated_text = 'تطبيق القسيمة';
    }
    if ('Please enter a coupon code.' === $text) {
        $translated_text = 'الرجاء إدخال رمز القسيمة.';
    }
    if ('Coupon code' === $text) {
        $translated_text = 'رمز الكوبون';
    }

    return $translated_text;
}

Please use the aboce code snippet.

mujuonly
  • 11,370
  • 5
  • 45
  • 75