Halloween Sale 15% off Ends in See the plans
PHP

Change Checkout Field Labels and Placeholders

Renames checkout fields and their placeholder hints, for example "Town / City" to "City" or "Apartment, suite, unit" to "Flat or floor", without a translation plugin.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_field_texts = array( // Field key => array( label, placeholder ).
    'billing_city'      => array( 'City', '' ),
    'shipping_city'     => array( 'City', '' ),
    'billing_address_2' => array( '', 'Flat, floor or building (optional)' ),
    'billing_phone'     => array( 'Mobile number', 'For delivery updates' ),
    'order_comments'    => array( 'Delivery notes', 'Gate code, safe place, etc.' ),
);

add_filter( 'woocommerce_checkout_fields', function ( $fields ) use ( $wpide_field_texts ) {
    foreach ( $fields as $group => $group_fields ) {
        foreach ( $wpide_field_texts as $key => $texts ) {
            if ( ! isset( $group_fields[ $key ] ) ) {
                continue;
            }

            if ( '' !== $texts[0] ) {
                $fields[ $group ][ $key ]['label'] = $texts[0];
            }

            if ( '' !== $texts[1] ) {
                $fields[ $group ][ $key ]['placeholder'] = $texts[1];
            }
        }
    }

    return $fields;
}, 20 );

Notes

Use full field keys such as billing_city or order_comments, and leave a value empty to keep WooCommerce's default.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.