API order price item is wrong
-
There is a problem with the price field in the order line_items derived from API.
The price in the product page is for example 11.10 while deriving the product prices via API in the order the price is for example 11.099999999999999999964565
What is this problem due to?
-
HI @andvsb,
How many decimals have you set in your WooCommerce → Settings → General → Number of decimals? WooCommerce does apply round-up by default (for instance, if I have two decimals settings, then 11.099999999999999999964565 would be rounded up to 11.10 in the front end and products page, as well as on the order page).
For instance, I just tested setting up an item with such a price: https://prnt.sc/Bd0YGmEzY4ZM
Here’s a test order (front end | back end | email).
I hope this helps so far!
-OPHi omarfpg!
How many decimals have you set in your WooCommerce → Settings → General → Number of decimals?
2
On frontend and in wordpress backend everything is ok, but if i call the order through API this is the result
Thanks!
Hey, @andvsb!
How are the taxes set up on your website?
If 11.10 is the price with the taxes, it might be that the actual price is the one showing through the API and on the front end it is rounding to two decimals.
Can you share screenshots of the tax settings (WooCommerce > Settings > Taxes and WooCommerce > Settings > Taxes > Standard rates)..
Furthermore, I’d like to understand your site properly. Please share with us the necessary information below for us to investigate the issue further:
System Status Report which you can find via WooCommerce > Status > Get system report > Copy for support.
Fatal error logs (if any) under WooCommerce > Status > Logs. Then you can use the selector to search for Fatal Errors.
You could copy and paste your reply here or paste it via https://gist.github.com/ and send the link here.Looking forward to your reply.
Have a wonderful day!
Hi carol i’ve made a fresh wordpress installation. No taxes (i’ve this problem even with taxes)
` ### WordPress Environment ### WordPress address (URL): https://tst3.visib italy.com Site address (URL): https://tst3.visib italy.com WC Version: 8.6.1 REST API Version: ✔ 8.6.1 WC Blocks Version: ✔ 11.8.0-dev Action Scheduler Version: ✔ 3.7.1 Log Directory Writable: ✔ WP Version: 6.4.3 WP Multisite: – WP Memory Limit: 1 GB WP Debug Mode: – WP Cron: ✔ Language: it_IT External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 8.0.30 PHP Post Max Size: 150 MB PHP Time Limit: 5400 PHP Max Input Vars: 12000 cURL Version: 8.6.0 OpenSSL/1.1.1w SUHOSIN Installed: – MySQL Version: 5.7.44-log Max Upload Size: 150 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 8.6.1 WC Database Prefix: wpts_ Total Database Size: 4.20MB Database Data Size: 2.50MB Database Index Size: 1.70MB wpts_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wpts_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wpts_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wpts_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wpts_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wpts_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wpts_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_options: Data: 1.42MB + Index: 0.06MB + Engine InnoDB wpts_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_posts: Data: 0.05MB + Index: 0.06MB + Engine InnoDB wpts_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wpts_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wpts_wc_admin_note_actions: Data: 0.05MB + Index: 0.02MB + Engine InnoDB wpts_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wpts_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_wc_orders: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wpts_wc_orders_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_wc_order_addresses: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wpts_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_wc_order_operational_data: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wpts_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wpts_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wpts_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wpts_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wpts_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wpts_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB ### Post Type Counts ### attachment: 1 page: 7 post: 2 product: 1 shop_order_placehold: 1 wp_navigation: 1 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ✔ ### Active Plugins (1) ### WooCommerce: by Automattic – 8.6.1 ### Inactive Plugins (0) ### ### Must Use Plugins (1) ### WordPress automation by Installatron: by – ### Settings ### API Enabled: – Force SSL: – Currency: EUR (€) Currency Position: right_space Thousand Separator: . Decimal Separator: , Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to Woo.com: – Enforce Approved Product Download Directories: ✔ HPOS feature screen enabled: ✔ HPOS feature enabled: ✔ Order datastore: Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore HPOS data sync enabled: – ### WC Pages ### Shop base: #7 - /negozio/ Cart: #8 - /carrello/ Checkout: #9 - /pagamento/ My account: #10 - /mio-account/ Terms and conditions: ❌ Page not set ### Theme ### Name: Storefront Version: 4.5.4 Author URL: https://woo.com/ Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔ ### Templates ### Overrides: – ### Admin ### Enabled Features: activity-panels analytics product-block-editor coupons core-profiler customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks product-variation-management product-virtual-downloadable product-external-affiliate product-grouped product-linked remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page Disabled Features: customize-store minified-js new-product-management-experience product-pre-publish-modal settings async-product-editor-category-field Daily Cron: ✔ Next scheduled: 2024-03-16 16:10:36 +00:00 Options: ✔ Notes: 63 Onboarding: completed ### Action Scheduler ### Complete: 5 Oldest: 2024-03-15 16:12:33 +0000 Newest: 2024-03-15 16:14:51 +0000 Failed: 1 Oldest: 2024-03-15 16:13:37 +0000 Newest: 2024-03-15 16:13:37 +0000 Pending: 1 Oldest: 2024-03-16 16:12:33 +0000 Newest: 2024-03-16 16:12:33 +0000 ### Status report information ### Generated at: 2024-03-15 16:20:30 +00:00 `thank you very much
-
This reply was modified 2 years, 2 months ago by
andvsb.
Hi andvsb,
On frontend and in wordpress backend everything is ok, but if i call the order through API this is the result
Thank you for the additional details. Now I understand the issue better, it’s when fetching the data in your API that you get the product price with all the decimals and you’d want it to be rounded up. The thing is your API must be pulling this data directly from the database and the database stores the price as is (ie on my product from yesterday: https://prnt.sc/znqtf8NM0nLk).
In this case, you’d need WooCommerce to actually save the prices by rounding them up, not just displaying them. This would count as customization, which is outside our support scope, though (learn more).
In this case, I recommend you ask in the WooCommerce Facebook group or the Woo Community Slack
#developerschannel. We’re lucky to have a great community of open-source developers for Woo, and many of our developers hang out there, as well.I can also recommend the Woo Developer Resources Portal for resources on developing for Woo. I’m also going to leave it open for a bit to see if anyone is able to chime in to help you out.
I hope this helps so far!
-OPHi omarfpg, I made a test in my demo area (fresh installation with 1 product and 1 order)
This is my product from backend, API and DB and all is ok
https://prnt.sc/9TMmfQrLq9GN https://prnt.sc/JMMsPt43rjUU https://prnt.sc/TG_TPS8BGh_NBut if you check the order line item price from API this is the result: https://prnt.sc/mSckLPHeYZ_b
I searched for those numbers in the database and the result was null https://prnt.sc/jpgfOTi-ltAB
Where those numbers are taken from?
Thanks
-
This reply was modified 2 years, 2 months ago by
andvsb.
Hi @andvsb,
Thank you for the additional details. So the product has a $12.99 price, both in front end, back end and in the database and you can also see this through your api, however when viewing the item as part of an order the price is showing up with a lot of decimals.
Can you share more details about this API you’re using, please? Can you share the exact steps you take to get the order info through this API, too? We’d like to try to replicate this to better understand this issue.
Thanks!
-OPHi omarfpg!
I’m using this API https://prnt.sc/4CCozSgwa9R3 and i see the results using Insomnia and through this
GET https://www.example.com/wp-json/wc/v3/orders/13?consumer_key=ck_XXXXX&consumer_secret=cs_XXXXX
My coder, who told me about this problem, is using curl.
Thanks
Hi @andvsb,
After reviewing all the details you’ve shared, it sounds like you are having line_item price inconsistency issue, as reported here. I tried recreating the issue on my testing site but had no luck.

However, to ensure we’re on the same page, can you confirm if this only occurs when the quantity is set to 1? I’d appreciate it if you could see what happens when you bump the quantity up to 2.
Also, is this happening with the latest version of WooCommerce? Do you have any custom settings or coding in place, or are you using the standard WordPress and WooCommerce setup? What are your Tax settings?
Furthermore, can you try this code snippet to see whether the problem gets resolved?
Let us know how that goes. Looking forward to hearing from you soon.
hi Shameem
from what I can see in your image the price was an integer and not a float, try changing the price from 37 to 37.99 to see if the problem shows up.
The order placed, as you can see from this image https://prnt.sc/NAQq8MtT0iXL, had quantity 1
I placed another order with quantity 2 and this is the result https://prnt.sc/r-DdCKDYhKPp
I am using version 8.7.0 of woocommerce and the site is a brand new test installation, taxes were not even set (the problem occurs even with taxes enabled)Thanks
Hi @andvsb,
Thank you for sharing further additional details! However, I’m still unable to reproduce the issue you’re facing. Following your suggestion, I set the floating pricing and checked the API response. Everything appears as expected.

Do you have any special settings, plugins, or custom code added that interfere with order details? Or are you using everything as default?
For better assistance, could you share a copy of your site’s System Status Report with us? You’ll find it at the top of the page under WooCommerce > Status > Select Get System Report and then Download for Support. This will download a TXT file containing the SSR’s contents to share with us. Once you have the System Status Report file, You can copy and paste your reply or share it via Mozilla Community Pastebin and share the link here.
Additionally, if you believe this might be a bug, I suggest you report it to our developer. You can do this by creating a report in our Github repo. Make sure to include all the relevant details so they can reproduce the error and provide further insights.
I hope this provides some clarity. Please let us know if you have any other questions!
Hi Shameem,
I don’t know why but if in /woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php I create a line_item field like this for example $data[‘test’] = 10.01 / 1; the result doesn’t come 10.01 but 10.0099999999999997868371792719699442386627197265625
I don’t know what it might be due to, whether the server or php, but if I make 10.01 / 1 in a woocommerce page template the result is correct.Thanks
Hi @andvsb,
It seems like you’re experiencing a floating point precision issue.
Are you, by any chance, making modifications to the core files? Could you share the reasons behind this? Also, are you using the legacy API instead of version 3? If that’s the case, have you switched on the Legacy API in your WooCommerce Settings?
For reference, these particular forums are meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:
- A local web developer
- Codeable.io
- WooExperts
I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.
Hi Shameem, I didn’t change anything in wordpress, I redid a clean install of wordpress and installed only woocommerce as a plugin but the problem still occurs.
I am not using Legacy API but REST API.
If this problem occurs, it is due to the fact that you use wc_format_decimal before doing the division by quantity instead of after.
I believe it is a woocommerce bug because I have tried it on two different servers and I am experiencing the same problem.
Thank youHi @andvsb,
The issue you’re describing seems related to how WooCommerce handles decimal values. However, the fact that you’re experiencing it even after a clean install and on different servers is quite unusual.
Although I couldn’t replicate the issue, and there are no known reports, I’d recommend submitting a bug report to our GitHub repository to investigate this issue further.
Please include all the details you’ve shared here and any additional information you think might be helpful. Our developers will then be able to look into the issue and provide further assistance.
In the meantime, I’d suggest manually updating WooCommerce to the latest version if you haven’t already done so. Sometimes, issues like these can be resolved with a simple update.
Thank you for your patience and understanding.
-
This reply was modified 2 years, 2 months ago by
The topic ‘API order price item is wrong’ is closed to new replies.