-
-
Save cryptexvinci/acfffd317ea6593d85f87191f92528c6 to your computer and use it in GitHub Desktop.
<?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; | |
} |
@cryptexvinci , this is not working for the postcode:-
$fields['shipping']['shipping_postcode']['label'] = __('Zipcode', 'woocommerce');
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';
}
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' );
// 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;
}
any update for woo 3.9 as the code to change the label does not work.
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;
}
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 );
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;
}
This doesn't seems to work with postcode field.
$fields['billing']['billing_postcode']['label'] = __'Some Label';