add checkout fields woocommerce code example
Example 1: woocommerce edit checkout fields
add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
function custom_override_checkout_fields($fields)
{
unset($fields['billing']['billing_address_2']);
$fields['billing']['billing_company']['placeholder'] = 'Business Name';
$fields['billing']['billing_company']['label'] = 'Business Name';
$fields['billing']['billing_first_name']['placeholder'] = 'First Name';
$fields['shipping']['shipping_first_name']['placeholder'] = 'First Name';
$fields['shipping']['shipping_last_name']['placeholder'] = 'Last Name';
$fields['shipping']['shipping_company']['placeholder'] = 'Company Name';
$fields['billing']['billing_last_name']['placeholder'] = 'Last Name';
$fields['billing']['billing_email']['placeholder'] = 'Email Address ';
$fields['billing']['billing_phone']['placeholder'] = 'Phone ';
return $fields;
}
Example 2: add bootstrap class to checkout fields woocommerce
add_filter('woocommerce_form_field_args', 'wc_form_field_args',10,3);
function wc_form_field_args($args, $key, $value) {
$args['input_class'] = array( 'form-control' );
return $args;
}
Example 3: add bootstrap class to checkout fields woocommerce
function wti_add_bootstrap_to_checkout_fields($fields) {
foreach ($fields as &$fieldset) {
foreach ($fieldset as &$field) {
$field['class'][] = 'form-group';
$field['input_class'][] = 'form-control';
}
}
return $fields;
}
add_filter('woocommerce_checkout_fields', 'wti_add_bootstrap_to_checkout_fields');