Making changes to checkout fields or adding custom fields to your checkout page #
Custom checkout fields can be added or changed on Fluid Checkout in the same way as for the original WooCommerce checkout.
There are two main ways you make changes to the checkout fields on your WooCommerce checkout page:
You should also be aware of some caveats regarding checkout field customizations when using Fluid Checkout. Read the section “Checkout field order caveats” in this article.
Using a checkout fields editor plugin (recommended method) #
Fluid Checkout is compatible with most checkout fields editor plugins for basic changes to the WooCommerce checkout fields. Basic changes would be:
- Change field label, description, and placeholder text
- Change field size and CSS classes
- Change field order (with caveats, see below)
- Remove or disable existing fields
- Add custom fields
Currently, we recommend using the plugin Checkout Field Editor for WooCommerce (by Themehigh), as we have tested and added full compatibility with it.
Advanced checkout fields customizations #
For advanced features, such as adding conditional fields and sections, you’ll need a compatible checkout field editor plugin that offers those advanced features, and the Fluid Checkout PRO plugin.
Currently, Fluid Checkout is only compatible with advanced features of the Checkout Field Editor for WooCommerce PRO (by Themehigh). Please note that to use these advanced features you’ll need the PRO version of both Fluid Checkout PRO and Checkout Field Editor for WooCommerce PRO (by Themehigh).
Using a code snippet #
Making changes to checkout fields via a custom PHP code snippet is significantly more difficult than using a checkout field editor plugin.
However, there are times when simple changes can be done via code snippets instead of having yet another plugin installed.
Fluid Checkout is fully compatible with the native WooCommerce filter hooks used to make changes to the checkout fields, be it to change labels, add new fields, or remove existing fields. Those filter hooks are:
woocommerce_billing_fields
woocommerce_shipping_fields
woocommerce_checkout_fields
Some examples of code snippets:
Making changes to billing fields using the filter hook woocommerce_billing_fields
:
/**
* Change billing address 1 field description.
*/
function fluidcheckout_change_billing_address_1_field_args( $fields ) {
// Bail if field is not present
if ( ! array_key_exists( 'billing_address_1', $fields ) ) { return $fields; }
$fields[ 'billing_address_1' ][ 'label' ] = __( 'Address line 1', 'your-text-domain' );
$fields[ 'billing_address_1' ][ 'description' ] = __( 'Address line 1 description here', 'your-text-domain' );
$fields[ 'billing_address_1' ][ 'placeholder' ] = __( 'Apartment, suite, unit...', 'your-text-domain' );
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'fluidcheckout_change_billing_address_1_field_args', 300 );
Making changes to shipping fields using the filter hook woocommerce_shipping_fields
:
/**
* Change shipping phone field label.
*/
function fluidcheckout_change_shipping_phone_label( $fields ) {
// Bail if shipping phone not available
if ( ! array_key_exists( 'shipping_phone', $fields ) ) { return $fields; }
$fields[ 'shipping_phone' ]['label'] = __( 'Phone', 'your-text-domain' );
// Uncomment the line below to change the field description
// $fields[ 'shipping_phone' ]['description'] = __( 'Your best phone number', 'your-text-domain' );
// Uncomment the line below to remove the field description
// $fields[ 'shipping_phone' ]['description'] = null;
return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'fluidcheckout_change_shipping_phone_label', 300 );
Making changes to billing fields using the filter hook woocommerce_checkout_fields
:
/**
* Swap the position of the billing first and last names to display the last name field first.
*/
function fluidcheckout_billing_last_name_first( $checkout_fields ) {
// Remove field size and position classes
if ( false !== ( $key = array_search( 'form-row-first', $checkout_fields['billing']['billing_first_name']['class'] ) ) ) { unset( $checkout_fields['billing']['billing_first_name']['class'][ $key ] ); }
if ( false !== ( $key = array_search( 'form-row-last', $checkout_fields['billing']['billing_last_name']['class'] ) ) ) { unset( $checkout_fields['billing']['billing_last_name']['class'][ $key ] ); }
// Change priority and add new appropriate size and position classes
$checkout_fields['billing']['billing_first_name']['priority'] = 20;
$checkout_fields['billing']['billing_first_name']['class'] = array_merge( $checkout_fields['billing']['billing_first_name']['class'], array( 'form-row-last' ) );
$checkout_fields['billing']['billing_last_name']['priority'] = 10;
$checkout_fields['billing']['billing_last_name']['class'] = array_merge( $checkout_fields['billing']['billing_last_name']['class'], array( 'form-row-first' ) );
return $checkout_fields;
}
add_filter( 'woocommerce_checkout_fields', 'fluidcheckout_billing_last_name_first', 300 );
If you are unsure about how to add the code snippet, check our article:
How to safely add code snippets to your WooCommerce website
There are a couple of things you need to keep in mind though:
- Fluid Checkout runs its fields customizations with a priority of
100
and200
, so any changes should be made with a higher priority. We recommend using a priority higher than300
. - Some plugins might use an even higher priority, for instance, Checkout Field Editor for WooCommerce (by ThemeHigh) uses a priority of
1000
, so ensure your customization code run at priority higher than that when using this plugin.
In case your changes are not taking effect, please try a higher priority value and see if it solves the issue.
Limitation: checkout field display order #
There is a limitation in Fluid Checkout regarding adding new fields, where the fields added to the shipping or billing section that does not have a correspondence in the other section will be displayed after the common fields.
For example, if you have custom fields for “Start date” and “End date” for an insurance policy added to the billing section, these fields will be displayed after the common billing address fields regardless of the order (priority) set for those fields via a checkout fields customization plugin or code snippet. However, if you add the corresponding fields to the shipping section, the fields will be displayed in the correct order as defined for both the billing and shipping sections.
Corresponding fields are fields that have the same ending on their field keys, for instance:
- billing_address_1 -> shipping_address_1
- billing_start_date -> shipping_start_date
- billing_end_date -> shipping_end_date
Although not ideal, this limitation is what makes it possible to use the option “(billing) same as shipping address” with a decent user experience.
We have a task on our backlog improve this in the future.
Limitation: Phone fields required #
In some cases, the shipping phone field might be forced to be required
if the billing phone field is set as required
, or vice-versa if you have the billing address section being displayed before the shipping address with Fluid Checkout PRO.
This is a limitation of how the checkout fields are copied from the one address section to the other. If the customer had not provided a value for the shipping phone field (set as optional
) and the billing phone is set as required
, and the customer chooses the option to copy the “billing address same as shipping address”, there would be no way enter a value for the phone field on the billing address section and it would not pass the validation criteria.
This limitation is related to the limitation of checkout fields display order above. We have a task on our backlog to improve this in the future.
Alternative solutions:
- If possible, set the billing phone field as
optional
; or - Move the billing phone field to the contact step: Move the “Phone” field to the contact step; or
- Use Fluid Checkout PRO to move the billing address section before the shipping address, this way you can se the billing phone as
required
and keep the shipping phone asoptional
.
Search Keywords #
customize fields, checkout fields, form fields, customize checkot, fiels