WooCommerce rename fields and make them required
The following code can be pasted in your functions.php file and works immediate.
add_filter( 'woocommerce_checkout_fields' , 'puddinq_override_checkout_fields' ); // Hooked in function - $fields is passed in the filter! function puddinq_override_checkout_fields( $fields ) { $fields['billing']['billing_address_1']['label'] = 'Street'; $fields['billing']['billing_address_1']['placeholder'] = 'Street'; $fields['billing']['billing_address_2']['label'] = 'Number'; $fields['billing']['billing_address_2']['placeholder'] = 'Number'; $fields['billing']['billing_address_2']['required'] = 1; $fields['shipping']['shipping_address_1']['label'] = 'Street'; $fields['shipping']['shipping_address_1']['placeholder']= 'Street'; $fields['shipping']['shipping_address_2']['label'] = 'Number'; $fields['shipping']['shipping_address_2']['placeholder']= 'Number'; $fields['shipping']['shipping_address_2']['required'] = 1; return $fields; }
To unravel the code above: the filter holds the $fields in an array. We change the values of the array to get what we want. We are changing both the ‘billing’ and shipping form, changing the address_1 and address_2 field labels and placeholder. In the case of address_2 we also set the required to 1 to make the field required.
- All other fields remain the same
- The fields will hold the same place in mails, and orders.