Remove default billing and shipping field
<?php
add_filter( 'woocommerce_default_address_fields', 'cxc_remove_billing_shipping_add_fields' );
function cxc_remove_billing_shipping_add_fields( $fields ) {
unset( $fields[ 'address_1' ] );
unset( $fields[ 'postcode' ] );
return $fields;
}
?>
<?php
add_filter( 'woocommerce_billing_fields', 'cxc_remove_billing_fields' );
function cxc_remove_billing_fields( $fields ) {
unset( $fields[ 'billing_address_1' ] ); // or shipping_address_2 for woocommerce_shipping_fields hook
unset( $fields[ 'billing_postcode' ] );
return $fields;
}
?>
Disable Shipping LastName Field Validation
<?php
add_filter( 'woocommerce_shipping_fields', 'cxc_remove_shipping_fields' );
function cxc_remove_shipping_fields( $fields ) {
unset( $fields[ 'shipping_last_name' ][ 'required' ] );
return $fields;
}
?>
Enabled Shipping Company Field Validation
<?php
add_filter( 'woocommerce_shipping_fields', 'cxc_shipping_compnay_required_fields' );
function cxc_shipping_compnay_required_fields( $fields ) {
$fields[ 'shipping_company' ][ 'required' ] = true;
return $fields;
}
?>
Changes In Both Billing And Shipping Address First Name Fields
<?php
add_filter( 'woocommerce_default_address_fields', 'cxc_billing_shipping_change_fname_field' );
function cxc_billing_shipping_change_fname_field( $fields ) {
$fields[ 'first_name' ][ 'label' ] = 'Name';
$fields[ 'first_name' ][ 'placeholder' ] = 'What is your name ?';
return $fields;
}
?>
Add Two Custom Fields In Both Billing And Shipping Address
<?php
//woocommerce_billing_fields, woocommerce_shipping_fields
add_filter( 'woocommerce_default_address_fields', 'misha_add_field' );
function misha_add_field( $fields ) {
$fields[ 'fav_color' ] = array(
'label' => __( 'Cxc Favorite color', 'cxc-codexcoach' ), // Add custom field label
'placeholder' => _x( 'Is it Yellow or Green or maybe Blue ...?', 'placeholder', 'cxc-codexcoach' ), // Add custom field placeholder
'required' => true, // if field is required or not
'clear' => true, // add clear or not
'class' => array( 'form-row-wide', 'cxc-custom-color-class' ), // add class name
'type' => "text", // add field type
'priority' => 20,
);
$fields['gst_numbers'] = array(
'label' => __( 'GST', 'cxc-codexcoach' ), // Add custom field label
'placeholder' => _x( 'Your GST Number here....', 'placeholder', 'cxc-codexcoach' ), // Add custom field placeholder
'required' => true, // if field is required or not
'clear' => false, // add clear or not
'class' => array( 'form-row-wide', 'cxc-custom-gst-class' ), // add class name
'type' => "text", // add field type
'priority' => 21, // add priority
);
return $fields;
}
?>
Was this article helpful?
YesNo