Skip Navigation

[Resolved] decimal places in third party fields

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 3.94 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by christopherM-10 4 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#1581995

Tell us what you are trying to do?
I'm trying to display the stock level of Woocommerce products to Admins and Shop Managers in the front-end
Is there any documentation that you are following?
No
Is there a similar example that we can see?
No
What is the link to your site?
hidden link (but you wouldn't see it if logged out)

I'm using the shortcode [wpv-post-field name='_stock'] placed in a Astra pro custom layout on a web hook into product pages, conditionally on user role. It works fine, except that the stock level is output with 6 decimal places, where the stock will always be a whole number. Can I format this field to show 0 decimal places?

Thanks.

#1582075

wpv-post-field will output whatever is stored in the Field, it is not very dynamic in reading third party input types.
I did not know WooCommerce stores that value with decimals, it makes poor sense, as you can't have 1.5 products in stock.

In fact, when I use this locally, on a WooCommerce site, I always get full integers.

Maybe you have some plugin or custom code in place that allows decimalizing in stock amounts?
In that case, it will make sense not to "change" that, as that code or plugin will have a reason to output decimals

Although I am pretty sure this will not work with WooCommerce native behaviours, there are many checks for "1 or 0", as opposed to "greater than 0" which would be required in a decimalized stock quantity.

#1582561

Yes, that makes sense. I have identified a plugin that is updating stock. After it does so, this happens, but I can't see the extra decimal places anywhere else. I'm checking with the developer. I hope they are helpful.
Thanks.