Title: Allow float amount
Last modified: March 24, 2020

---

# Allow float amount

 *  Resolved [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/)
 * Thanks again for great plugin and great updates.
    One of our needs is to add 
   and reduce amount in float. it’s used for example to sell fruits in Kg. I have
   changed the plugin’s code in order to access float amount. and it worked by changing
   some absint( $data[‘quantity’] ) to floatval( $data[‘quantity’] ) and change 
   the type of amount from integer to float for update and add item.
 * It would be appreciated if you do this modification in new update.

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/allow-float-amount/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/allow-float-amount/page/2/?output_format=md)

 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12576382)
 * How does being able to add a float value work for quantity?
 *  Thread Starter [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12583641)
 * We can do it in this way. Of course my code checks if the product measurement
   is not quantized then does the following.
 *     ```
       // Add step value to the quantity field (default = 1)
       add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal');
       function nsk_allow_decimal($val) {
           	return 0.5;
       }
       add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 ); // Simple products
   
       function jk_woocommerce_quantity_input_args( $args, $product ) {
           	$args['step'] = 0.5;
       	return $args;
       }
       // Removes the WooCommerce filter, that is validating the quantity to be an int
       remove_filter('woocommerce_stock_amount', 'intval');
   
       // Add a filter, that validates the quantity to be a float
       add_filter('woocommerce_stock_amount', 'floatval');
       ```
   
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12583688)
 * I understand the possibility now. I will look further into this.
 *  Thread Starter [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12584028)
 * Thanks a lot. Is this included in version 2.0.11?
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12584037)
 * No. As I said I will be looking into this further. Will let you know if it’s 
   included in the next release.
 * Your welcome to push your change to the CoCart GitHub repository and I will test
   the change you have made. You will also be given credit for your contribution.
 * How does that sound?
 *  Thread Starter [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12584306)
 * Oh sure. Thank you.
    I forked it. I’ll do the changes and push.
    -  This reply was modified 6 years, 2 months ago by [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/).
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12588408)
 * Here are my test results before and after your request change. Please let me 
   know if it looks correct to you with the totals.
 * ### Before with a singular quantity value.
 *     ```
       json
       {
           "4818e3493e7621149b6906333721e341": {
               "addons": [],
               "key": "4818e3493e7621149b6906333721e341",
               "product_id": 32,
               "variation_id": 0,
               "variation": [],
               "quantity": 1,
               "data": {},
               "data_hash": "b5c1d5ca8bae6d4896cf1807cdf763f0",
               "line_tax_data": {
                   "subtotal": {
                       "13": 8.4
                   },
                   "total": {
                       "13": 8.4
                   }
               },
               "line_subtotal": 42,
               "line_subtotal_tax": 8.4,
               "line_total": 42,
               "line_tax": 8.4,
               "product_name": "Hoodie",
               "product_title": "Hoodie",
               "product_price": "£42.00"
           }
       }
       ```
   
 * ### After with a float value for quantity.
 *     ```
       json
       {
           "4818e3493e7621149b6906333721e341": {
               "addons": [],
               "key": "4818e3493e7621149b6906333721e341",
               "product_id": 32,
               "variation_id": 0,
               "variation": [],
               "quantity": 2.032123,
               "data_hash": "b5c1d5ca8bae6d4896cf1807cdf763f0",
               "line_tax_data": {
                   "subtotal": {
                       "13": 17.0698332
                   },
                   "total": {
                       "13": 17.0698332
                   }
               },
               "line_subtotal": 85.34916600000001,
               "line_subtotal_tax": 17.07,
               "line_total": 85.34916600000001,
               "line_tax": 17.07,
               "data": {},
               "product_name": "Hoodie",
               "product_title": "Hoodie",
               "product_price": "£42.00"
           }
       }
       ```
   
 *  Thread Starter [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/allow-float-amount/#post-12593424)
 * Yes Sébastien. It’s true. It needs also a test for update too. I think it has
   different route in code.
 * Of course we do not calculate tax. But it seems ok. I just used 0.5 for amount
   change.
    -  This reply was modified 6 years, 2 months ago by [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/).
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12596016)
 * Tax needs to be tested along with several quantity examples. I do not want to
   make this change and it ends up breaking for those who are using it as it is 
   now. So please test test test.
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12598907)
 * Next release ready for public testing.
 * [https://github.com/co-cart/co-cart/releases/tag/v2.0.13-rc.1](https://github.com/co-cart/co-cart/releases/tag/v2.0.13-rc.1)
 *  Thread Starter [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12605819)
 * Thanks a lot.
    I think tax calculation is ok. Because the calculation is from
   woocommerce core. And [is officially allowed in the docs](https://docs.woocommerce.com/document/adjust-the-quantity-input-values/).
 * I try to install and test.
    Thank you.
    -  This reply was modified 6 years, 1 month ago by [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/).
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12608267)
 * I hope so. The filter you showed only affects the default values for the quantity
   input on the frontend. Nothing else so can’t really say 100%!
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12625157)
 * How is the testing going [@sefid-par](https://wordpress.org/support/users/sefid-par/)?
 *  Thread Starter [Mohammad Etemaddar](https://wordpress.org/support/users/sefid-par/)
 * (@sefid-par)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12629963)
 * Yes, It worked Sébastien.
 *  Plugin Author [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * (@sebd86)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/#post-12632123)
 * I filtered the `woocommerce_stock_amount` filter in CoCart. Can you make sure
   after disabling the filter you did yourself that it still works. Thank you.

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/allow-float-amount/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/allow-float-amount/page/2/?output_format=md)

The topic ‘Allow float amount’ is closed to new replies.

 * ![](https://ps.w.org/cart-rest-api-for-woocommerce/assets/icon-256x256.png?rev
   =3220815)
 * [CoCart - Headless REST API for WooCommerce](https://wordpress.org/plugins/cart-rest-api-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cart-rest-api-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cart-rest-api-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/cart-rest-api-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cart-rest-api-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cart-rest-api-for-woocommerce/reviews/)

 * 18 replies
 * 2 participants
 * Last reply from: [Sébastien Dumont](https://wordpress.org/support/users/sebd86/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/allow-float-amount/page/2/#post-12632212)
 * Status: resolved