By default, Fluid Checkout will copy all fields in the shipping address section to the billing address section with a matching field key (ie. billing_address_1
-> shipping_address_1
) when the checkbox “[Billing address] same as shipping address” is checked.
In some cases, you might need to allow copying only the shipping address fields, excluding other fields fields such as the First and Last name fields.
You can use the code snippet below to change the list of fields that will be copied from the shipping address to the billing address:
/**
* Change list of billing address fields for copying values from shipping address.
*/
function fluidcheckout_change_billing_same_as_shipping_field_keys( $field_keys ) {
$field_keys = array_diff( $field_keys, array( 'billing_first_name', 'billing_last_name' ) );
return $field_keys;
}
add_filter( 'fc_billing_same_as_shipping_field_keys', 'fluidcheckout_change_billing_same_as_shipping_field_keys', 10 );
add_filter( 'fc_substep_text_billing_address_field_keys_skip_list', 'fluidcheckout_change_billing_same_as_shipping_field_keys', 10 );
If you are unsure about how to add code snippet to your website, check our article:
How to safely add code snippets to your WooCommerce website
Fields that are removed from the copied fields from the shipping address section to billing will appear below the checkbox “[Billing address] same as shipping address” without any value, and the customer will be requested to enter a value for required fields as usual.