Home / eCommerce / Change WooCommerce Coupon Code Entry Field Placeholder and Apply Button Text
Duplicate Snippet

Embed Snippet on Your Site

Change WooCommerce Coupon Code Entry Field Placeholder and Apply Button Text

# Changes coupon code entry field placeholder text from "Coupon code" to "Enter coupon code".
# Changes coupon code apply button text from "Apply coupon" to "Apply".
## It does NOT change input name="coupon_code" or button name="apply_coupon" so 'apply' functionality remains intact.
### Works seamlessly with separate snippet to rename "Coupon" terminology to "Discount" but can also be used without separate renaming snippet.

Code Preview
php
<?php
if ( class_exists( 'WooCommerce' ) ) {
    // Run after RD renaming snippet (in case enabled)
    add_filter( 'gettext', 'rd_wc_coupon_text_overrides', 30, 3 );
    function rd_wc_coupon_text_overrides( $translated, $original, $domain ) {
        if ( is_admin() ) {
            return $translated;
        }
        if ( ! ( function_exists( 'is_cart' ) && function_exists( 'is_checkout' ) ) ) {
            return $translated;
        }
        if ( ! ( is_cart() || is_checkout() ) ) {
            return $translated;
        }
        // Apply button label: always "Apply"
        if ( $original === 'Apply coupon' || $translated === 'Apply coupon' || $translated === 'Apply Coupon' ) {
            return 'Apply';
        }
        // Placeholder/label: prepend "Enter " to whatever the final translated text is
        // This allows the rename snippet to turn "Coupon code" -> "Discount code" first.
        if ( $original === 'Coupon code' || $translated === 'Coupon code' || $translated === 'Coupon Code' || $translated === 'Discount code' || $translated === 'Discount Code' ) {
            // If already starts with Enter, don't double up
            $t = trim( $translated );
            if ( stripos( $t, 'Enter ' ) === 0 ) {
                return $t;
            }
            // Sentence case after "Enter "
            return 'Enter ' . strtolower( $t );
        }
        return $translated;
    }
}

Comments

Add a Comment