Important advice: Never touch WooCommerce plugin core files avoiding:
- Important errors
- Losing the changes you have done when plugin is updated
To customize WooCommerce you can:
To edit / create / remove / reorder checkout fields we can use this 2 filter hooks:
'woocommerce_checkout_fields'
or in specific cases you need to use the
'woocommerce_default_address_fields'
(applied to all billing & shipping default fields below)
Here the list of billing and shipping default fields:
country
first_name
last_name
company
address_1
address_2
city
state
postcode
For example, to make the 'billing_state'
field required:
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_default_address_fields( $address_fields ) {
// we are changing here billing_state field to required
$address_fields['billing']['billing_state']['required'] = true;
return $address_fields;
}
Each field contains an array of properties that you can edit:
type – type of field (text, textarea, password, select)
label – label for the input field
placeholder – placeholder for the input
class – class for the input
required – true or false, whether or not the field is require
clear – true or false, applies a clear fix to the field/label
label_class – class for the label element
options – for select boxes, array of options (key => value pairs)
Checkout fields are divided into 4 groups:
- shipping fields
- billing fields
- account fields
- order fields (notes, comments)
References: