How to Change Apply Coupon Button Text In WooCommerce

WooCommerce Change Apply Coupon Button Text

Are you looking for a way to change the apply coupon button text on the cart and checkout page?

Coupons are an excellent way of keeping customers in your store engaged.

They encourage customers to complete the purchase so that they can get a coupon.

You can also use them as incentives to entice loyal customers.

However, you may want to change the apply button text on the cart and checkout pages.

You should not worry, as it is not a complicated process to achieve this.

But you need some coding skills to use this solution.

WooCommerce does not have a built-in option to achieve this. This is why we will use a custom PHP code snippet.

WooCommerce Change Apply Coupon Button Text

By the end of this post, you should be able to change the apply coupon button on the cart and checkout page.

However, we recommend that you use a child theme to make changes. This will ensure that your changes are not lost when an update occurs.

Let us look at how you can achieve this.

Steps to Change the Apply Coupon Button Text

This is how the Apply Coupon button is displayed on the cart and checkout page respectively:cart coupon checkout coupon

Here are the steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will change the apply coupon button on the cart and checkout page.
  3. Add the following code to the functions.php 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;

}
  1. This is the outcome on the cart and checkout page respectively:change cart voucher change Checkout voucher

Conclusion

In this post, we have shared a custom PHP snippet that allows you to change the coupon code button on the cart and checkout page.

If you are not comfortable with handling code, we recommend that you contact a qualified WordPress developer.

This is because if you make any error in the functions.php file, it will break down your site.

Similar Articles