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...
  • Frequently Asked Questions
    • Frequently Asked Questions...
  • Compatible Plugin & Themes
    • Plugins & Themes...
  • 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/Repeat Rules: More use cases and examples

Repeat Rules: More use cases and examples

Last updated on October 17, 2022

 Case 1: Repeat field or section based on product quantity of a specific category.

If you need to repeat a field or section based on the quantity of products in a specific category, you can use below code snippet.

add_filter('thwcfe_repeat_times', 'th27mb_override_repeat_count', 10, 3);
function th27mb_override_repeat_count($rt, $name, $type){
global $woocommerce;
$count = array();
$cart_object = WC()->cart->get_cart();
$category = 'accessories'; // category slug

if($cart_object){
foreach($cart_object as $cart_item ) {
if(has_term( $category, 'product_cat', $cart_item['product_id'])){
$qty = $cart_item['quantity'];
array_push($count,$qty);
}
}
}

if(empty($count)){
return $rt;
}

if($type == 'field'){

if($name === 'test_field'){ // update field name
$rt = array_sum($count);
}

}elseif($type == 'section'){

if($name === 'test_section'){ // update section name
$rt = array_sum($count);
}

}

return $rt;
}

Case 2: Repeat field or section based on the largest quantity of product in cart items.

If you need to repeat a field or section, you can add a repeat rule in field or section settings.

Recently there is a request to modify the repeat count based on the large quantity of products in cart items.

add_filter('thwcfe_repeat_times', 'th34ed_override_repeat_count', 10, 3);
function th34ed_override_repeat_count($rt, $name, $type){
global $woocommerce;
$cart_count = array();
$cart_object = WC()->cart->get_cart();

if($cart_object){
foreach($cart_object as $cart_item ) {
$qty = $cart_item['quantity'];
array_push($cart_count,$qty);
}
}

if(empty($cart_count)){
return $rt;
}

if($type == 'field'){

if($name === 'test_field'){ // update your field name
$rt = max($cart_count);
}

}elseif($type == 'section'){

if($name === 'test_section'){ // update your section name
$rt = max($cart_count);
}

}

return $rt;
}
Get the plugin

On this page

  • Case 1: Repeat field or section based on product quantity of a specific category.
  • Case 2: Repeat field or section based on the largest quantity of product in cart items.

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

© 2025 ThemeHigh. All rights reserved.

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