Skip to content
Fluid Checkout
  • Features
  • Demo
  • Pricing PRO
  • Docs
  • Support
  • My account
0,00 € 0 items
Home / Docs / Configure cart quantity fields for decimal quantities

How can we help?

Getting started

  • Do I need to uninstall the free version, or is Fluid Checkout Lite required?
  • How to translate Fluid Checkout plugins into your language

Account & Purchases

  • Can I get a refund for my purchase?
  • Finding my invoice, adding billing details and VAT number

Customizations

  • Configure cart quantity fields for decimal quantities
  • Move the “Phone” field to the first step (contact step)
  • How to change the icon or icon color for the cart button on mobile
  • Customizing checkout fields and adding custom checkout fields
  • How to customize WooCommerce or Fluid Checkout template files
  • How to add a new house number field and make it required
  • How to safely add code snippets to your WooCommerce website

Licenses

  • New versions updates are not appearing on my website

Features

  • Local Pickup — Hide shipping address when local pickup is selected
  • Trust symbols — add security badges, trust seals and other trust symbols to strategic places on the checkout, cart and order received pages
  • International phone numbers — formatting and validation for phone numbers based on country rules
  • Edit cart at checkout — change quantity or remove items from the cart directly at the checkout page
  • Express checkout — quick payment buttons for Google Pay, Apple Pay and other payment methods

Development

  • Troubleshoot – Trust symbols widgets randomly moving to other areas when switching themes
  • Changelog format and semantic version numbers
  • Changelog – Fluid Checkout PRO & Lite

Configure cart quantity fields for decimal quantities

Table of Contents
  • The case for decimal quantities
  • Enabling decimal quantities for product stock
  • Enabling decimal quantities with Fluid Checkout PRO optimized cart and checkout pages

The case for decimal quantities #

By default, WooCommerce only allow whole numbers for the quantity fields. However, the use of decimal quantities in WooCommerce can be beneficial in various scenarios:

  • Products Sold by Weight or Length: If you sell products that are measured by weight or length, such as fruits, vegetables, fabric, or liquids, decimal quantities allow customers to purchase precise amounts. For example, a customer may want to buy 0.5 kg of apples or 1.75 meters of fabric. Enabling decimal quantities allows for accurate purchasing based on weight or length.
  • Flexible Measurement Units: Decimal quantities are useful for products that are measured using non-integer units, such as liquids, powders, or granules. For example, if you sell spices by weight or liquids by volume, decimal quantities allow customers to purchase precise amounts, such as 0.5 kg of spices or 1.75 liters of liquid.
  • International Units: Decimal quantities are commonly used for products with international measurement units. For example, if you sell products in a country that uses decimal-based units, such as kilograms, liters, or meters, decimal quantities allow for accurate and precise purchasing based on local measurement standards.
  • Customizable Products: Decimal quantities can be helpful for products that customers can customize or configure. For instance, if you offer products with multiple options or variations, such as custom fabric by the yard or custom paint by the liter, decimal quantities allow customers to specify exact measurements for their customized products.
  • User Convenience: Enabling decimal quantities can enhance the user experience for customers. It allows them to purchase products in the exact quantity they need, without being limited to whole numbers. This can be particularly useful for customers who require precise quantities for their specific needs.

Enabling decimal quantities for product stock #

WooCommerce does not have a built-in setting to enable decimal quantities. However, you can achieve this functionality through the use of third-party plugins or custom code.

Here are some possible ways to enable decimal quantities for products in WooCommerce:

  • Use a WooCommerce plugin: There are several third-party plugins available in the WooCommerce plugin marketplace that add decimal quantity functionality to your store. You can search for plugins using keywords such as “decimal quantities” or “decimal quantities for WooCommerce” to find suitable options.
  • Implement custom code: If you are comfortable with coding, you can implement custom code to enable decimal quantities for products in WooCommerce. Please note that custom code implementation requires careful consideration and testing to ensure compatibility with your theme and other plugins, and it’s recommended to backup your site before making any changes.

It’s important to note that enabling decimal quantities may have implications for inventory management, shipping calculations, and other aspects of your WooCommerce store. Therefore, thorough testing and consideration of the implications of decimal quantities is recommended before implementing this functionality on a live store.

Enabling decimal quantities with Fluid Checkout PRO optimized cart and checkout pages #

Once you have enabled decimal quantities on WooCommerce, you might need to configure Fluid Checkout PRO to allow decimal quantities on the optimized cart page and on the checkout page if the feature to allow customers to edit cart quantities at checkout is enabled.

To configure decimal quantities for the cart quantities on Fluid Checkout PRO, you need to add the following code snippets to your website, adapting it to the correct number steps for the increase “+” and decrease “-” buttons and the number of decimal places you use for quantities on your website.

If you are unsure about how to add the code snippet to your website, check our article:
How to safely add code snippets to your WooCommerce website

Change number of decimal places for quantity fields

/**
 * Change quantity fields expected decimal places for the number spinner script.
 */
function fluidcheckout_change_cart_items_quantity_field_decimal_places( $decimal_places, $cart_item, $cart_item_key, $product ) {
    return 1;
}
add_filter( 'fc_pro_cart_items_quantity_decimal_places', 'fluidcheckout_change_cart_items_quantity_field_decimal_places', 300, 4 );

Change quantity fields increase/decrease step

This code snippet will only change the quantity step attribute on the cart and checkout pages. You might not need to use if your custom code or the plugin you use for enabling decimal quantities already sets this attribute for other pages on your website.

/**
 * Change quantity fields increase/decrease step amount on cart and checkout pages.
 */
function fluidcheckout_maybe_change_cart_items_quantity_step( $step, $product ) {
    // Bail if not on cart or checkout pages
    if ( ! class_exists( 'FluidCheckout_Steps' ) || ( ! FluidCheckout_Steps::instance()->is_cart_page_or_fragment() && ! FluidCheckout_Steps::instance()->is_checkout_page_or_fragment() ) ) { return $step; }

    return .5;
}
add_filter( 'woocommerce_quantity_input_step', 'fluidcheckout_maybe_change_cart_items_quantity_step', 300, 2 );

Allow decimal values for stock quantities

Your custom code or the plugin you use for enabling decimal quantites probably already replaces the stock quantity filter hooks to use a data type that allows decimal values, but here is the code snippet to do that, for the sake of completeness:

/*
 * Replace conversion of stock quantity from integer to float values
 */
remove_filter( 'woocommerce_stock_amount', 'intval', 10 );
add_filter( 'woocommerce_stock_amount', 'floatval', 10 );
What are your Feelings
Still stuck? How can we help?

How can we help?

Updated on April 19, 2023
Move the “Phone” field to the first step (contact step)
Table of Contents
  • The case for decimal quantities
  • Enabling decimal quantities for product stock
  • Enabling decimal quantities with Fluid Checkout PRO optimized cart and checkout pages
Fluid Checkout

Frictionless Multi-step Checkout for WooCommerce

© 2021-2023 Fluidweb OÜ

Terms | Refunds | Privacy Policy | Cookies | Affiliates

Products
  • All products
  • Fluid Checkout PRO
  • Fluid Checkout Lite
  • Google Address Autocomplete for WooCommerce
Company
  • Support
  • My account
  • About
  • Home
  • Home
  • Features
  • Pricing PRO
  • Demo
  • Docs
  • Support
  • My account