Wednesday 27 July 2016

How to Rename Coupon Code fields with WooCommerce, WordPress?


Just renaming the coupon field to something else can likewise diminish the quantity of clients that leave your site amid checkout to discover coupon codes. Clients that as of now have the code will comprehend what name to search for whatever length of time that you're steady. For instance, on the off chance that you email out "Offer Codes" or "Promo Codes", then clients will search for this field, yet those without coupons won't get occupied by the words "coupon" or 'rebate'.

Simply following the steps of code changing for rename the coupon code fields.

Add following code in "functions.php" file.


<?php
/************************************************
 * rename the coupon field on the cart page
 ************************************************/
function woocommerce_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 ( 'Apply Coupon' === $text ) {
$translated_text = 'Apply Promo Code';
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );



/************************************************
 * rename the "Have a Coupon?" message on the checkout page
 ************************************************/
function woocommerce_rename_coupon_message_on_checkout() {
return 'Have a Promo Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';
}
add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );
// rename the coupon field on the checkout page
function woocommerce_rename_coupon_field_on_checkout( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
if ( 'Coupon code' === $text ) {
$translated_text = 'Promo Code';

} elseif ( 'Apply Coupon' === $text ) {
$translated_text = 'Apply Promo Code';
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_checkout', 10, 3 );

?>

Above bold text place do rename as you need.



For more Interesting, Useful Article & codes visit IT New Code.

Ankit Shah PHP Expert

IT New Code suggest a solution for your problem related to coding, Specially .PHP, Wordpress, WooCommerce, Magento, HTML and CSS. Visit Our website for Information.

4 comments:

  1. Thank you for sharing your tutorial. It works as advertised. I did however have to make a minor adjustment. All instances of 'Apply Coupon' needed to be changed to 'Apply coupon' (with a lower case 'c').

    ReplyDelete
  2. Do you know how to change the message that comes up AFTER you enter a coupon code? The default says "Coupon code applied successfully"

    ReplyDelete
  3. thanks for the info,
    my problem is how can i rename the Coupon does not exist! when a wrong coupon in entered.

    ReplyDelete
  4. Exactly where in the functions.php do add the suggested code?

    ReplyDelete

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah