Changing the WooCommerce coupon text in cart and checkout pages
Want to change the WooCommerce coupon text… there are a few areas that need to be tackled namely the cart and the checkout pages, WooCommerce has most of the filters needed and the gettext filter can finish off translating the text string.
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 = '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 bt_rename_coupon_message_on_checkout() { return 'Have a coupon code?' . ' ' . __( 'Click here to enter your code', 'woocommerce' ) . ''; } function bt_rename_coupon_label( $err, $err_code=null, $something=null ){ $err = str_ireplace("Coupon","Voucher Code ",$err); return $err; }
Add the above in functions.php the example changes ‘coupon’ for ‘voucher’.
Related Posts:
- Disable WooCommerce Payments credit card/debit card…
- Change WooCommerce Checkout Page To A 2-Column Layout
- Position WooCommerce Checkout Spinning Icon On Page
- Remove add to cart button on WooCommerce products…
- How to compress and uncompress files and folders in…
- Completely hide WooCommerce products from shop,…
- Set up WordPress cron to run via server cron in…
- Set up malware scanner LMD Maldet and ClamAV on a…