ResolvedChange coupon to discount – WooCommerce

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26909
    IainBeaumont
    Participant

    Dear Althemist,

    I would like to change the word coupon to discount during the cart & checkout phase of WooCommerce. I have tried using the following code within the Child functions.php folder (which works on my other WooCommece sites) but to no effect.

    add_filter( ‘gettext’, ‘woocommerce_rename_coupon_field_on_cart’, 10, 3 );
    add_filter( ‘gettext’, ‘woocommerce_rename_coupon_field_on_cart’, 10, 3 );
    add_filter(‘woocommerce_coupon_error’, ‘rename_coupon_label’, 10, 3);
    add_filter(‘woocommerce_coupon_message’, ‘rename_coupon_label’, 10, 3);
    add_filter(‘woocommerce_cart_totals_coupon_label’, ‘rename_coupon_label’,10, 1);
    add_filter( ‘woocommerce_checkout_coupon_message’, ‘woocommerce_rename_coupon_message_on_checkout’ );

    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 ( ‘Coupon:’ === $text ) {
    $translated_text = ‘Discount Code:’;
    }

    if (‘Coupon has been removed.’ === $text){
    $translated_text = ‘Discount code has been removed.’;
    }

    if ( ‘Apply coupon’ === $text ) {
    $translated_text = ‘Apply Code’;
    }

    if ( ‘Coupon code’ === $text ) {
    $translated_text = ‘Discount Code’;

    }

    return $translated_text;
    }

    // rename the “Have a Coupon?” message on the checkout page
    function woocommerce_rename_coupon_message_on_checkout() {
    return ‘Have a Discount Code?’ . ‘ ‘ . __( ‘Click here to enter your code’, ‘woocommerce’ ) . ”;
    }

    function rename_coupon_label($err, $err_code=null, $something=null){

    $err = str_ireplace(“Coupon”,”Discount Code “,$err);

    return $err;
    }

    Please can you advise what I need to do in respect of the BabyStreet theme?

    Kind regards

    Iain

    #26912
    Althemist
    Keymaster

    Hello Iain,

    I am afraid that’s not theme related. It’s part of the WooCommerce functionality, so we can’t really help with this.

    However, if the only thing you want to do is changing the name of the coupon related fields, there is no need to write custom functions. Just use Loco translate and change the text string to whatever you want.

    Loco Translate

    Regards,
    Dimitar

    #26917
    IainBeaumont
    Participant

    Hi, thank you for your response.

    I have found a temporary workaround (added to functions.php) until I can specify to WooCommerce

    add_filter( ‘gettext’, ‘change_coupon_text’, 20, 3);
    function change_coupon_text( $translated_text, $text, $text_domain){
    $text = str_replace( “Coupon”, “Discount”, $text );
    $text = str_replace( “coupon”, “Discount”, $text );
    return $text;
    }

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in and have valid license to reply to this topic.

License required for any item belonging to this account
AlThemist

AlThemist

sales 17365, followers 742
Login and Registration Log in · Register