Skip Navigation

[Resolved] Numerical Field Values

This support ticket is created 3 years, 9 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 6.90 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1964513
tech_japan.JPG

Tell us what you are trying to do?

I am trying to display an imported or manually added price using the localized format of our clients site / currency.

¥1,234 ... when the input value is 1234

We are using the following Types code to present the price:

¥[wpv-post-field name="_price"]

We have also used

¥[wpv-post-field name="_regular_price"]

Sometimes, this is successful. We have about 700 products and most of them take an input value and display it correctly, such as on this link:

hidden link

The price output, about 1/2 way down the page is: 価格(税別): ¥4,880

However, this adjacent item doesn't work:

hidden link

On that page you can see the output is 価格(税別): ¥4880

Is there any documentation that you are following?

Nothing specific - just some google searching and forum searching for how to display the price value without the whole woocommerce add to cart invocation

On the attached image, we tried exporting all of the data, and noticed that in Excel, the fields that cause problems appear to Excel to be formatted as General Text, instead of as a Numerical value. In that screenshot, #1 identifies one of the examples above that shows up without the numerical formatting, adjacent to the item below, which does appear with numerical formatting in WordPress. The 'comma' appearing on excel in this image is not present in the field value, it's being added by Excel when it displays the data from the Export because that's how it treats numerical fields. #2 shows it is registering as General instead of Number, #3 shows how it appears on the website and #4 shows how we are invoking the price.

Also on the backend of WordPress, all of the pricing in the admin interfaces work correctly.

Is there a similar example that we can see?

We created this item by hand, instead of an import:

hidden link

We thought that if it was an import issue, making one by hand would 'fix' the issue.

We also tried manually changing price values .... going from 1234 to 1235 for example, or to zero, and then back ... no luck there.

What is the link to your site?

hidden link

#1965077

Hi,

Thank you for contacting us and I'd be happy to assist.

Based on the information you've shared, I understand that this is a case where the price values that you think are showing correctly are the ones that are stored incorrectly in the database. And the ones which you think are showing incorrectly are actually stored correctly.

The reason is that it is recommended to store numeric fields like prices, as numeric values (e.g. 12345) without any formatting or thousand separators (e.g. 12,345).

When formatting or thousand separator information is stored in the value, it is treated as a string/text and not a numeric value which results in unexpected results in logical or numerical comparisons like sorting/ordering or lower than or greater than, etc.

WooCommerce also stores numeric values in its price fields, which is why you're seeing the price without thousand separators in the manually added "Yen Test Product" product.

The Toolset's shortcode "wpv-post-field" ( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field ) gets the raw custom field value from the database. For all products where you're seeing the price with a thousand separators, they'll need to be updated to have only a numeric value.

Once the data storage part is taken care of, you can format the numeric values for the front-end display using a custom shortcode, as suggested in this reply:
https://toolset.com/forums/topic/i-want-to-arrange-my-homes-by-price-lowest-to-highest/#post-1951997

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar