// Hook in
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['order']['order_comments']['placeholder'] = 'Special delivery requirements';
$fields['billing']['billing_company']['label'] = 'Company name if applicable';
$fields['shipping']['shipping_company']['label'] = 'Company name if applicable';
$fields['billing']['billing_address_2']['placeholder'] = 'House number / name';
$fields['shipping']['shipping_address_2']['placeholder'] = 'House number / name';
$fields['billing']['billing_state']['required'] = true;
$fields['billing']['billing_state']['label'] = 'County <abbr class="required" title="required">*</abbr>';
return $fields;
}
I’ve used thIs code to change some fields for the woocommerce checkout form.
For some inexplicable reason, the label for the billing state refuses to change. Even though the label for billing company had changed the successfully, the label for the billing state refuses to. It has successfully become required but I can’t change the label.
Does anyone know what I am doing wrong or if this is a bug.
You have to use the
woocommerce_default_address_fields
hook:This (and more) is described at the woocommerce docs: Customizing checkout fields using actions and filters, so read your stuff next time thoroughly… 😉
Edit:
Above code isn’t working for all cases, because on country selection the state field of the checkout form gets updated via javascript. To make it work it’s necessary to add the desired name for those cases as translation, using the
woocommerce_get_country_locale
hook like this:The hook is located at the
class-wc-countries.php
in theget_country_locale()
function.I know this was some time ago but I would like to add a little to this thread if only to save some others the same frustration I experienced.
There are some fields in the checkout page that just won’t change regardless of the filter you use these fields are due to the
checkout.js
file. This file loads locale information from the current locale and resets the fields labels and placeholder those values. this was particularly frustrating when trying to change the placeholder “Street address” to PO Box/Street addressWhat needs to be done to change these fields is to set a locale in you
wp_config.php
file something like:Then download the plugin “codestyling localisation”
go to Tools->Localization, scroll down to woocommerce and rescan your language file, in this case it would be the English/United Kingdom file.
After it has scanned click edit and search for your term, in this case “Street address” and add your translation in my case that was “Street address/PO Box”.
click the “generate mo-file” button at the top and you are done, full instructions on how to do this at:
http://docs.woothemes.com/document/woocommerce-localization/