-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order amount changed when saving (due to unexpected scientific notation numbers) #28613
Comments
@marcochiesi Thanks for reporting the issue. I tested this with WooCommerce 5.8.0 and the discount amount on the product was rounded correctly:
Are you still experiencing this issue? |
Hello @rrennick |
@marcochiesi Thanks for the follow up. |
Hi @marcochiesi , Thank you for the updated information on this issue. However, we couldn't reproduce it using the steps provided you. Everything works as expected on our end using WordPress 5.8.2 and WooCommerce 5.9.0 version. Below is the screencast documenting my experience : 28613.mp4Please provide us with more details and any additional steps required to repro this issue which may help us to evaluate it further. |
Thanks @swatipawarGS for your screencast but it appears to show the price remains the same after pressing update. Can you try again but make sure to include in your screencast all the steps in the original report? |
Hi @marcochiesi , Thank you for submitting the issue. However, I can’t reproduce it using the steps you provided. Everything is working as expected on my end using WooCommerce 5.9.0 version. Below is the screencast documenting my experience : 28613.2.1.mp4 |
Hello @tammullen and @swatipawarGS |
P.s. For the sake of completeness, I confirm the bug is still present on a vanilla WordPress 5.8.2 with WooCommerce 5.9.0 (being the only plugin installed), and it can be reproduced by following accurately the step-by-step instructions listed in the very first post of this thread. |
Hi @marcochiesi , Thank you for the updated information on this issue. However, we couldn't reproduce it using the steps provided you. Everything works as expected on our end using WordPress 5.8.2 and WooCommerce 5.9.0 version. Below is the screencast documenting my experience : 28613.mp4Please provide us with more details and any additional steps required to repro this issue which may help us to evaluate it further. |
@swatipawarGS In your latest video, you do not show all the steps provided in the initial instructions, so I suspect you didn't enter the exact same amounts for the products and the coupon that were provided in the initial report. Please follow accurately all the instructions and you should be able to reproduce the issue. See also the video attached to the initial report; even if it was based on a previous version of WooCommerce, the situation is the same also with the latest one. Please let me know if you want me to record a new video with the latest version. |
Hi @marcochiesi , Thank you for the updated information. We confirm that the issue is reproducible on our end as well using WooCommerce 5.9.0 version and WordPress 5.8.2 version. Below is the screencast documenting my experience : 28613.2.mp4Priority of this issue will be assigned shortly after we’d go through a round of prioritization. Please note it may take a couple of days. |
Prerequisites (mark completed items with an [x]):
Describe the bug
In some circumstances, when simply saving the order from the WooCommerce backend, the order amount values get changed.
Expected behavior
When saving an order, amounts shouldn't be changed arbitrarily.
Actual behavior
The order total gets changed when simply saving the order (when some specific values are present).
This occurred on a production site but it can be reproduced on a vanilla WP with WooCommerce being the only plugin installed and with a default theme.
At first, I couldn't believe my eyes, but after further investigation, I found that the described bug depends on the presence of some very small float number in the
line_tax
fields that can be present after applying taxes and discounts. These values are rendered in the order edit form with the scientific notation (i.e. -8,0E-5). They appear as 0,00€ visually in the order table, but the hidden input gets the value in the scientific notation. When the form is submitted, those values are interpreted as integers, so i.e.-8,0E-5€ becomes -8€, and it changes also the total of the order.
This is caused by the
wc_format_localized_price
function, which internally uses thestrval
function, which can return strings with numbers in scientific notation (i.e. 0.00008 becomes -8.0E-5).This is the current implementation of that function:
At the moment I have used the following trick to detect and avoid the conversion to scientific notation:
Only replacing
strval
withsprintf
would lead to a lot of undesired side effects in other parts of the interface, so I preferred to explicitly detect the case of scientific notation and only act in that case.Since this is a critical bug, I hope it can be fixed in WooCommerce as soon as possible. I would be glad to submit a pull request if the above approach would be considered valid (maybe there are better ways to fix the issue, i.e. let the scientific number notation be accepted when saving).
Steps to reproduce the bug (We need to be able to reproduce the bug in order to fix it.)
Steps to reproduce the bug:
.
and decimal separator to,
and saveScreenshots
See a full video recording (4 minutes) here: https://drive.google.com/file/d/1TJDqD4xnmSXXv8yS5v740S9XOrTUX-xl/view?usp=sharing
Isolating the problem (mark completed items with an [x]):
WordPress Environment
WordPress address (URL): http://woo-test-2.local
Site address (URL): http://woo-test-2.local
WC Version: 4.8.0
REST API Version: ✔ 4.8.0
WC Blocks Version: ✔ 3.8.1
Action Scheduler Version: ✔ 3.1.6
WC Admin Version: ✔ 1.7.3
Log Directory Writable: ✔
WP Version: 5.6
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: en_US
External object cache: –
Server Environment
Server Info: nginx/1.16.0
PHP Version: 7.3.5
PHP Post Max Size: 1,000 MB
PHP Time Limit: 1200
PHP Max Input Vars: 4000
cURL Version: 7.64.0
OpenSSL/1.1.1b
SUHOSIN Installed: –
MySQL Version: 8.0.16
Max Upload Size: 300 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔
Database
WC Database Version: 4.8.0
WC Database Prefix: wp_
Total Database Size: 3.70MB
Database Data Size: 2.32MB
Database Index Size: 1.38MB
wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_options: Data: 1.48MB + Index: 0.03MB + Engine InnoDB
wp_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_posts: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
Post Type Counts
attachment: 1
page: 6
post: 2
product: 2
shop_coupon: 1
shop_order: 4
Security
Secure connection (HTTPS): ❌
Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
Hide errors from visitors: ✔
Active Plugins (1)
WooCommerce: by Automattic – 4.8.0
Inactive Plugins (0)
Settings
API Enabled: –
Force SSL: –
Currency: EUR (€)
Currency Position: left
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 WooCommerce.com: –
WC Pages
Shop base: #6 - /shop/
Cart: #7 - /cart/
Checkout: #8 - /checkout/
My account: #9 - /my-account/
Terms and conditions: ❌ Page not set
Theme
Name: Twenty Twenty-One
Version: 1.0
Author URL: https://wordpress.org/
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: –
Action Scheduler
Complete: 12
Oldest: 2020-12-17 13:31:29 +0000
Newest: 2020-12-17 13:53:07 +0000
The text was updated successfully, but these errors were encountered: