WP SITES

3095 Coded Tutorials & 297 Plugins

Conditional Fields For Contact Block Using Block Checkout

The code in this download folder enables you to add conditional fields to the contact information block when using the block checkout in WooCommerce.

Note : The code will not work with the old woocommerce checkout shortcode.

The code adds 3 fields in the contact location :

  1. A checkbox which once checked shows the a conditional field.
  2. A conditional select field. When the option named other is selected, the next field displays.
  3. A text field which displays conditionally when the select field equals a value of other.

Here’s the checkbox which displays by default on page load :

Contact information form with an email address input field and an optional checkbox labeled 'Enable Options'.

Followed by the conditional select field :

Screenshot of a contact information form with fields for email address, a checkbox labeled 'Enable Options (optional)', and a dropdown for selecting an option.

Which then displays a text field when a specific option is selected :

Contact information form displaying an email field, an optional enable checkbox, a select dropdown with an 'Other' option, and a conditional text field.

Demo Video

Shows the 3 fields added to the contact information block and shown conditionally based on field values.

Installation

  1. Copy and paste the PHP code to the end of your child themes functions file or custom code snippets plugin.
  2. Modify the values for the labels and values for the options.

Related Coded Solutions

Was this helpful?

Yes
No
Thanks for your feedback!

Leave a Reply