ThemeHigh
  • Plugins
  • Documentation
  • Support
  • Partners
  • Login
  • Getting Started
    • Overview...
    • Add/Edit Custom Fields
    • Set Display Rules
    • Set Repeat Rules
    • Price Fields & Types
    • User Meta Fields
    • Time Picker Settings
    • Why Your Checkout Fields Aren’...
    • Date Picker Settings
    • Display Custom Fields...
  • Advanced Settings
    • Include New Fields in Address Format?
    • Enable Address Autofill
    • Configure Locale Override Settings
    • Add Custom Fields to CSV Export
    • Display Custom Fields In PDF Invoices & Packing Slips
    • Zapier Support
    • Display Country & State Fields based on Conditional Rules
    • WPML Compatibility
    • Where do the Custom Fields get Saved or Displayed?
    • Backup & Import Settings
    • Enable Inline Validation...
    • WPML String Translations...
    • Custom Fields in WooCommerce Orders
    • Add a New Custom Validation Rule
    • Add a New Confirm Field Validator
    • Import/Export the Checkout Fields and Sections
  • For Developers
    • Hooks & References...
    • Display Rules: Use cases and mor...
    • Repeat Rules: More use cases and...
    • Based on Checkout Fields: Use ca...
    • Override HTML Content: Examples...
    • Compatibility with “WooCom...
  • Compatible Plugin & Themes
    • Plugins & Themes...
  • Frequently Asked Questions
    • Frequently Asked Questions...
  • How
    • How To Display Fields In Order D...
    • How To Customise The Shipping Se...
    • How To Add Custom Fields In The ...
    • How to Add Custom Price Fields o...
    • How To Add A New Section To The ...
    • How To Display Custom Fields In ...
    • How to Show/Hide Fields Based On...
    • How To Set Repeat Rules On The C...

Documentation/Checkout Field Editor for WooCommerce/Display Rules: Use cases and more examples

Display Rules: Use cases and more examples

Last updated on October 17, 2022

Case 1: Conditionally display checkout field based on day & time

If you like to display a checkout field on a specific time in a specific day in week, you can use below code snippet.

The below code snippet will show a checkout field named asĀ field_name in between 7 AM & 6 PM for all days except weekends (Sunday & Saturday).

function thwcfe_show_checkout_field($show, $field_name){
if($field_name == 'field_name'){
$show = false;
$currentDateTime = current_time('H:i:s');
$current_time = strtotime($currentDateTime);
$start_time = strtotime('07:00:00');
$end_time = strtotime('18:00:00');

$weekend = array('Sun','Sat');
$day = current_time('D');

if($current_time > $start_time && $current_time < $end_time && !in_array($day, $weekend)){
$show = true;
}
}
return $show;
}
add_filter('thwcfe_show_field', 'thwcfe_show_checkout_field', 10, 2);

Case 2: Display checkout section based on saved user data

If you are using the Checkout Editor plugin, you can save the checkout field data as user meta.

In a few situations, we need to display checkout page sections based on these saved user data. Remember that this is only possible for logged in users.

Use the below code snippet in your theme’s or child theme’s functions.php file. Update the user meta key, values, and section identifier in the code snippet with your details.

function thwcfe_conditional_section_hide($show, $section_name){
if(is_user_logged_in()){
$user_id = get_current_user_id();
$user_meta = get_user_meta($user_id, 'billing_first_name', true);

if($user_meta === 'saved_user_data'){
if($section_name == 'section_name'){
$show = false;
}
}
}

return $show;
}
add_filter('thwcfe_show_section', 'thwcfe_conditional_section_hide', 10, 2);

Case 3: Display checkout field if the cart quantity is more than one

This code snippet is useful to display the checkout field if the cart quantity is more than one using WooCommerce Checkout Field Editor Pro plugin.

Use the below code snippet in your theme’s or child theme’s functions.php file. Update the string {field_name} in the filter tag in the code snippet with your field name.

function thwcfe_show_field_condition($show){

global $woocommerce;
$count = $woocommerce->cart->cart_contents_count;
if($count < 1){
$show = false;
}

return $show;

}

add_filter('thwcfe_show_field_{field_name}', 'thwcfe_show_field_condition');

Case 4: Conditionally display checkout fields

There are already too many inbuilt conditions available in the WooCommerce Checkout Field Editor plugin.

But if you have some amazing conditions that are not covered by our plugin, here is a simple code snippet for you to display or hide checkout fields based on your conditions.

Use the below code snippet in your theme’s or child theme’s functions.php file. Update the string {field_name} in the filter tag in the code snippet with your field name.

function thwcfe_show_field_condition($show){

// Your conditions here
// $show Variable have the value True or False as per the field settings in your backend
// Return True to display the field
// Return False to hide the field

}

add_filter('thwcfe_show_field_{field_name}', 'thwcfe_show_field_condition');

Case 5: Add a fee based on selected date by date-picker custom checkout field

First create new checkout field with date picker using Checkout Field Editor plugin. You must add a price for that input field.

Then use below code snippet in your theme’s or child theme’sĀ functions.phpĀ file. Update the stringĀ {field_name}Ā in filter tag in the code snippet with your field name.

function thwcfe_change_total_price($price, $value){

// Get today date
$current_time = date( 'd/m/Y', current_time( 'timestamp', 0 ) );
$today = DateTime::createFromFormat('d/m/Y', $current_time);
$today->setTime( 0, 0, 0 );

// Get selected date using date picker
$selected_date = DateTime::createFromFormat('d/m/Y', $value);
$selected_date->setTime( 0, 0, 0 );

// Find the difference between dates
$diff = $today->diff( $selected_date );
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval

// Conditionally add fee using switch statement
switch( $diffDays ) {
case 0: // for Today
$price = '';
break;
case -1: // for Yesterday
$price = '';
break;
case +1: // for Tomorrow
$price = $value;
break;
default: // for Sometime
$price = '';
}

return $price;

}
add_filter('thwcfe_checkout_field_extra_cost_{field_name}', 'thwcfe_change_total_price',10,2);

Case 6: Show checkout field based on cart items shipping class

If you like to show a checkout field based on cart items shipping class, you can use below code snippet.

function th3er4_show_field_based_on_shipping_class($show, $field_name){
if(!is_checkout()){
return;
}
if($field_name != 'your_field_name'){
return $show;
}
global $woocommerce;
$show = false;
$cart_object = WC()->cart->get_cart();
$shipping_class='test_shipping_class';
if($cart_object){
foreach($cart_object as $cart_item ) {
$product = $cart_item['data'];
$class = $product->get_shipping_class();
if($class === $shipping_class){ 
$show = true;
break;
} 
}
}
return $show;
}
add_filter('thwcfe_show_field', 'th3er4_show_field_based_on_shipping_class', 99, 2);

Please note that you need to replace your_field_name with the field name that you wish to set the conditional rule. Also, please replace test_shipping_class with your corresponding shipping class name.

Get the plugin

On this page

  • Case 1: Conditionally display checkout field based on day & time
  • Case 2: Display checkout section based on saved user data
  • Case 3: Display checkout field if the cart quantity is more than one
  • Case 4: Conditionally display checkout fields
  • Case 5: Add a fee based on selected date by date-picker custom checkout field
  • Case 6: Show checkout field based on cart items shipping class

What's new

  • Added a custom file upload button property for the File upload field type.
  • Alert on selecting display position of sections as before/after terms and conditions.
  • Added Woocommerce 6.8.2 compatibility.

Highlights

  • 24 custom field types with file upload.
  • Create additional sections.
  • Display sections and Fields Conditionally.
  • Display custom fields at 14 different positions.
  • Create confirm field validators.
  • Price fields with a set of price types.
  • Repeat fields and sections based on specific conditions.
  • WPML Compatibility.
  • Import & Export fields and sections.

This article posted in Checkout Field Editor for WooCommerce, For Developers, Pro Documentation

Leave a Reply Cancel reply

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

ThemeHigh

We develop innovative WordPress plugins and themes for e-commerce and other WordPress websites.

Resources
  • Documentation
  • Support
  • Blog
  • Bestsellers
  • Affiliates
  • Partners
Policy Information
  • Terms & Conditions
  • Privacy Policy
  • Support Policy
  • Refunds Policy
  • Licenses
Security
Payment Options

Ā© 2026 ThemeHigh. All rights reserved.

Terms and conditions, features, support, pricing, and service options subject to change without notice.