• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WP Desk = premium plugins for WordPress & WooCommerce
  • Plugins
        • Checkout & OrdersMake your work easier and automate the orders. Adjust the order form to your needs and make it more useful to your customers. Print order labels directly from WooCommerce. Put the orders in order using our plugins. Find out how to streamline the procurement process in your store.
          • Flexible Checkout Fields
          • Active Payments
          • Automatic Payment Status
          • Flexible Refund and Return Order
          • Print Orders and Address Labels
          • Flexible Subscriptions Recurring Shipping
          • Flexible Subscriptions Payment Retry
          • Flexible Subscriptions Stock Management
        • ProductsThese plugins will help you manage your WooCommerce products. Here you will find the plugins to import and update products from XML or CSV files. Then you can change the product unit of measure, show the lowest price in the last 30 days (Omnibus Directive), or let customers name the product price!
          • Flexible Product Fields
          • Dropshipping Import Products
          • Dropshipping FTP Import Products
          • Dropshipping Export Products
          • Custom Price
          • WP Desk Omnibus
          • Flexible Quantity Calculator
          • Dropshipping Orders Export
        • MarketingPromote your store online. Add products from your shop to price comparison websites directly from WooCommerce. Acquire new customers and communicate with your existing ones. Build a customer base and communicate with clients using one of the most effective marketing tools, namely e-mail marketing. Check out our promotional tools!
          • Flexible Pricing
          • Flexible Wishlist - Analytics & Emails
          • OLX WooCommerce
          • Flexible PDF Coupons
          • ShopMagic
          • Flexible Invoices
  • Bundle🔥
  • WP Desk Care
  • Support
  • Blog
  • My Account
  • 0

More results

How to set conditional logic based on the number of products in the cart

WooCommerce checkout fields

Tomasz Drzewiecki3 minutes read2026-06-06
blog category heading image
  1. Why is conditional logic useful in my store?
  2. Conditional logic in the Flexible Checkout Fields plugin
  3. Condition Cart contains > Number of items
  4. Combining several conditional logic rules in one field
  5. Summary

Contents

  • Why is conditional logic useful in my store?
  • Conditional logic in the Flexible Checkout Fields plugin
  • Condition Cart contains > Number of items
  • Combining several conditional logic rules in one field
  • Summary
    • Related Articles
  • Take Control of WooCommerce Edit Checkout Fields Using Smart Conditional Logic
  • How to Add Conditional Logic to the Country Field in WooCommerce checkout?
  • WooCommerce Conditional Logic, Custom Fields & Product Options in one plugin!
  • Best plugin to speed up WooCommerce Checkout (conditional & custom fields)
  • How to show or hide a WooCommerce checkout field for a specific country

Why is conditional logic useful in my store?

Conditional logic for WooCommerce checkout fields always has one primary purpose. The idea is that the store customer fills out only those fields that are actually necessary to complete the purchase. You will probably be discouraged if you feel that the store requires more information from you than necessary. Even if the mere fact of providing personal information does not discourage you, you will probably be discouraged by the feeling of wasting your time filling out a long form.

WooCommerce offers only one type of conditional logic here, and it is rather invisible at first glance. This happens when the cart contains only products that do not require shipping - then the shipping fields (those with the shipping prefix, e.g. shipping_first_name) are hidden. But that's it.

Conditional logic in the Flexible Checkout Fields plugin

Conditional logic is composed of two basic concepts - condition and action. If the condition is met, the action is triggered. In a WooCommerce checkout, an action usually means showing or hiding a field, or setting it as required.

Click on the image to enlarge it

EXAMPLE #1
If the cart contains a product from the Gifts for her category, show the Wrap as a gift checkbox.

The Flexible Checkout Fields plugin, from version 4.0.0, offers extensive conditional logic settings, including completely new conditions (marked in bold):

  • Cart contains
    • Product
    • Category
    • Product type
    • Number of items (how many products are in the cart)
  • Cart (what is the total value of the cart)
  • FCF field (if the field added by the FCF plugin have the appropriate value)
  • Shipping method
  • Woo fields (if the field added by WooCommerce have the appropriate value)
  • User (what is their role in the store)
  • Payment method
  • Date (what is the date and time of completing the form)
  • FPF field (if the field added by the Flexible Product Fields plugin have the appropriate value)

Condition Cart contains > Number of items

Where did the idea to add the Cart contains > Number of items condition to the Flexible Checkout Fields conditional logic come from? These and other ideas (needs) are regularly reported to us by plugin users, and one scenario appeared very often.

What does the store sell?
Only virtual products - personalized tickets.

What does the store need?
Additional information about the ticket holder - such as their name and e-mail address.
Saving this additional information with the order.

What is the solution?
Conditional logic Cart contains > Number of items.

The Cart contains > Number of items condition allows you to perform the action if the number of products in the cart corresponds to the numerical values ​​(x) given in the settings:

  • Is (x)
  • More than (x)
  • Less than (x)

Setting up such conditional logic in the plugin panel is simple and comes down to configuring one line:

  1. Select a field (or add a new one), e.g. Name on ticket no. 1 and click the Conditional Logic tab.
  2. Click Group 1 - additional options will appear.
  3. Select an action, e.g. Show this field – additional options will appear.
  4. Set Rule #1 (first condition):
    Cart contains > Number of items > More than > 0
Click on the image to enlarge it

EXAMPLE #2
If there is at least 1 product in the cart, the Name on ticket no. 1 field will appear in the checkout form.

The following fields are set similarly:

  1. Select a field (or add a new one), e.g. Name on ticket no. 2 and click the Conditional Logic tab.
  2. Click Group 1.
  3. Select an action, e.g. Show this field.
  4. Set Rule #1:
    Cart contains > Number of items > More than > 1

EXAMPLE #3
If there is 1 product in the cart, the Name on ticket no. 1 field will appear in the checkout form.
If there are 2 products in the cart, the fields Name on ticket no. 1 and Name on ticket no. 2 will appear in the checkout form.

Combining several conditional logic rules in one field

Examples #2 and #3 describe a situation when all products in the store require additional information (always the same). However, it is possible that there are other products in the store that do not require providing a name and e-mail address - then showing the Name on the ticket field does not make much sense. In this case, an additional condition (Rule #2) will be necessary to exclude such products and narrow the scenario:

  1. Select the Name on ticket #1 field and click the Conditional Logic tab.
  2. Click Group 1.
  3. Click the And button in the Rule #1 row - additional options will appear.
  4. Set Rule #2 (second condition):
    Cart contains > Category > Which is > Tickets
Click on the image to enlarge it

EXAMPLE #4
If there is at least 1 product in the cart and it contains a product from the Tickets category, the Name on ticket no. 1 field will appear in the checkout form.

Summary

The conditional logic of the Flexible Checkout Fields plugin includes all the basic components of a purchase form, such as: cart, shipping and payment methods, WooCommerce fields and user role. If we add further, less obvious (but useful) conditions, such as the FCF and FPF fields and the date, we get a complete tool that allows us to handle even the most complicated purchase scenarios, e.g. showing a field only to a user from a specific country (more on this topic in the article How to Add Conditional Logic to the Country Field in WooCommerce checkout).

Related Articles

WooCommerce conditional checkout fields

Take Control of WooCommerce Edit Checkout Fields Using Smart Conditional Logic

In this guide, you'll learn how to configure conditional logic for checkout fields in your WooCommerce store. I'll guide you step by step through the ...
How to Add Conditional Logic to the Country Field in WooCommerce checkout?

How to Add Conditional Logic to the Country Field in WooCommerce checkout?

If you've ever found yourself scratching your head, wondering how to make your WooCommerce checkout page smarter and more user-friendly, you're in for...
WooCommerce conditional product options and variations

WooCommerce Conditional Logic, Custom Fields & Product Options in one plugin!

Last year we released our plugin for adding product options, custom fields, and customizing your WooCommerce products. Many customers asked us to add ...
Best plugin to speed up WooCommerce Checkout (flexible options)

Best plugin to speed up WooCommerce Checkout (conditional & custom fields)

Having a very slow WooCommerce checkout may result in losing customers! Today, I will show our best plugin to speed up your WooCommerce checkout page ...
Hide checkout fields WooCommerce based on country

How to show or hide a WooCommerce checkout field for a specific country

Setting a shipping zone for a country opens the way to show or hide a WooCommerce checkout field only for customers from that country. All the necessa...

3 minutes read17449 views

Tomasz Drzewiecki

Tomek is a QA Engineer at WP Desk, working in IT since 2014 and part of the WP Desk team since 2020. His goal is to ensure WP Desk applications are...

Powered by WP Desk

WP Desk brings you great WooCommerce plugins. We strive to save your time and money by speeding up your processes. Use our plugins to build a better store. Awesome support included in the package.

Premium WooCommerce Plugins →
WP Desk › Blog › WooCommerce checkout & orders › WooCommerce checkout fields › How to set conditional logic based on the number of products in the cart

Primary Sidebar

Contents

  • Why is conditional logic useful in my store?
  • Conditional logic in the Flexible Checkout Fields plugin
  • Condition Cart contains > Number of items
  • Combining several conditional logic rules in one field
  • Summary

Flexible Checkout Fields PRO WooCommerce £59

Edit, add new or hide unnecessary fields from the WooCommerce checkout form. Add pricing to fields and use conditional logic. It's all about conversions and better user experience. NEW: now you can set multiple conditions (OR) under one or more condition groups (AND).

💾 Active Installations: 80,000+ | WordPress Rating:

Add to cart or View Details
WP Desk
80,000+ Active Installations
Last Updated: 2026-08-20
Works with WooCommerce 10.7 - 11.1

Stay updated on our how-to articles

WP Desk news, WooCommerce tips, promo codes - right to your inbox.

By entering your e-mail, you agree to our Terms & Conditions and Privacy Policy.

By entering your e-mail, you agree to our Terms & Conditions and Privacy Policy.

Footer

WP Desk - WooCommerce Plugins

At WP Desk we create great WooCommerce plugins with awesome support. Save time and money with our e-commerce solutions. See how we can help you improve your e-store →

Secured by Comodo

WP Desk

  • About us
  • Giving Back
  • Blog
  • Get Support
  • Contact us

Products

  • Premium Plugins
  • WP Desk Care
  • Documentation
  • WooCommerce Invoices
  • Email Marketing
  • PDF Coupons

Legal

  • Terms & Conditions
  • Refund Policy
  • Support Policy
  • Privacy Policy

© 2026 WP Desk

We value your privacy

We use necessary cookies to make our site work. We'd also like to set additional cookies to understand site usage, enhance your browsing experience, and serve personalized ads or content. By clicking ‘Accept All,’ you consent to our use of additional cookies.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}