WooCommerce: Moving and Editing Fields on the Checkout Page

checklist, check, list

The WooCommerce checkout page is a critical area of customization for many store owners. Adjusting the placement of fields and fine-tuning their text can significantly enhance user experience and usability.

A recent inquiry in the Business Bloomer Club discussed moving a checkbox with an associated action and editing field text due to incomplete translations.

This article dives into practical steps to manage such customizations effectively, even when custom plugins add complexity. Let’s explore how you can modify your WooCommerce checkout layout and text without resorting to overkill solutions or excessive expenses.

Moving Fields on the Classic Checkout Page

WooCommerce provides the flexibility to rearrange checkout fields through hooks and filters. If you’re looking to move simple fields, such as the email field, it can be done using a few lines of code. However, for fields added by plugins—like a checkbox with a post-click action—the process can be more complex.

Moving Built-In Fields

To move a standard field, such as the email field, you can use the following snippet:

add_filter('woocommerce_checkout_fields', 'move_email_field_to_top');
function move_email_field_to_top($fields) {
    $email_field = $fields['billing']['billing_email'];
    unset($fields['billing']['billing_email']);
    $fields['billing'] = ['billing_email' => $email_field] + $fields['billing'];
    return $fields;
}

This snippet moves the email field to the top of the billing section. You can adjust the array order to reposition other fields similarly.

Moving Plugin-Added Fields

For fields added by plugins, like those from GermanMarket/B2BMarket, the task involves identifying how the plugin injects the field.

  1. Inspect the Plugin Code: Look for the hook or function used to add the field.
  2. Remove the Field: Use remove_action or remove_filter to detach it from its original position.
  3. Reposition the Field: Use the relevant WooCommerce hooks to place it where needed.

For example:

remove_action('woocommerce_checkout_field_action', 'plugin_function');
add_action('woocommerce_after_order_notes', 'plugin_function');

Editing Field Text or Translations

Incomplete translations in plugins or themes can often be resolved by using WooCommerce filters or translation tools.

Using a Filter to Edit Text

To change the text of a specific field, use the following code:

add_filter('woocommerce_checkout_fields', 'edit_checkout_field_text');
function edit_checkout_field_text($fields) {
    $fields['billing']['billing_phone']['label'] = __('Your Contact Number', 'woocommerce');
    return $fields;
}

Updating Translations

For plugin or theme translations:

  1. Use Loco Translate to adjust text strings.
  2. Alternatively, manually update .po and .mo files for your language.

Advanced Customizations

If plugins complicate the process, some additional steps might help:

  • Debug Plugin Behavior: Check how the plugin’s actions tie into WooCommerce hooks.
  • Consult Plugin Documentation: Some plugins offer detailed guides for customizing their fields.

Conclusion

Customizing WooCommerce checkout fields is a mix of using built-in hooks and dealing with plugin-specific challenges. For standard fields, code snippets suffice, while plugin-added elements might require diving into the plugin code to modify their placement. Editing translations is straightforward with filters or translation tools. By following these strategies, you can ensure your WooCommerce checkout is optimized for usability and functionality.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *