Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Last active December 20, 2023 09:48
Show Gist options
  • Save cryptexvinci/acfffd317ea6593d85f87191f92528c6 to your computer and use it in GitHub Desktop.
Save cryptexvinci/acfffd317ea6593d85f87191f92528c6 to your computer and use it in GitHub Desktop.
Rename WooCommerce checkout field label & placeholder
<?php
// WooCommerce Rename Checkout Fields
add_filter( 'woocommerce_checkout_fields' , 'custom_rename_wc_checkout_fields' );
// Change placeholder and label text
function custom_rename_wc_checkout_fields( $fields ) {
$fields['billing']['billing_first_name']['placeholder'] = 'Wonka';
$fields['billing']['billing_first_name']['label'] = 'Your Awesome First Name';
return $fields;
}
@Developer-Amit
Copy link

@cryptexvinci , this is not working for the postcode:-
$fields['shipping']['shipping_postcode']['label'] = __('Zipcode', 'woocommerce');

@rahuladams
Copy link

rahuladams commented Apr 12, 2018

Those who can't get it done with the above code, Try this:

add_filter( 'woocommerce_default_address_fields' , 'checkout_custom_labels' );
function checkout_custom_labels( $address_fields ) {
     $address_fields['postcode']['label'] = 'Pin Code';
}

@sarveshacharya
Copy link

sarveshacharya commented Apr 15, 2018

Following one works well with latest version:

function custom_override_default_address_fields( $address_fields ) {
$address_fields['address_1']['label'] = 'Address';
$address_fields['address_1']['placeholder'] = 'Address Line 1';
$address_fields['address_2']['placeholder'] = 'Address Line 2';

return $address_fields;

}

add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );

@auludag
Copy link

auludag commented Jul 25, 2018

// following zipcode code works with WooCommerce 3.4

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_postcode']['placeholder'] = '21343';
$fields['billing']['billing_postcode']['label'] = 'Posta Kodu ';
return $fields;
}

@foamymedia
Copy link

any update for woo 3.9 as the code to change the label does not work.

@AmeenJalali
Copy link

any update for woo 3.9 as the code to change the label does not work.
// Tested with woocommerce 3.9.1:
add_filter( 'woocommerce_default_address_fields' , 'override_default_address_fields' );
function override_default_address_fields( $address_fields ) {
$address_fields['address_1']['label'] = 'Shipping Address';
$address_fields['address_1']['placeholder'] = 'Your Complete Shipping Address';
return $address_fields;
}

@nfsarmento
Copy link

nfsarmento commented Sep 3, 2020

For those that are having issues in translate/change WooCommerce fields, just use gettext filter. Tested with the latest WooCommerce version.

function imde_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Postcode' :
            $translated_text = __( 'Postcode (Required)', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'imde_text_strings', 20, 3 );

@wellyington
Copy link

Works with WooCommerce 8.4.0

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_postcode']['label'] = 'Postal Code ';
return $fields;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment