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.
-
How does being able to add a float value work for quantity?
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');I understand the possibility now. I will look further into this.
Thanks a lot. Is this included in version 2.0.11?
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?
Oh sure. Thank you.
I forked it. I’ll do the changes and push.-
This reply was modified 6 years, 1 month ago by
Mohammad Etemaddar.
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" } }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, 1 month ago by
Mohammad Etemaddar.
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.
Next release ready for public testing.
https://github.com/co-cart/co-cart/releases/tag/v2.0.13-rc.1
Thanks a lot.
I think tax calculation is ok. Because the calculation is from woocommerce core. And is officially allowed in the docs.I try to install and test.
Thank you.-
This reply was modified 6 years, 1 month ago by
Mohammad Etemaddar.
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%!
How is the testing going @sefid-par ?
Yes, It worked Sébastien.
I filtered the
woocommerce_stock_amountfilter in CoCart. Can you make sure after disabling the filter you did yourself that it still works. Thank you. -
This reply was modified 6 years, 1 month ago by
The topic ‘Allow float amount’ is closed to new replies.