In PHP 8 required parameters after optional parameters in
function/method signatures trigger a deprecation notice. These type
of parameters are pointless since a value needs to always be
provided for them anyway, so they are actually de-facto required.
This commit converts all these not-so-optional parameters into
truly required parameters by removing their default values.
There's a number of places in the WooCommerce codebase where the
built-in function 'round' is executed passing a non-numeric value
(not a number and not a string that can be parsed as a number),
for example round(''). In PHP 7 this yields a value of 0, but in
PHP 8 this throws an error.
This commit adds a 'NumberUtil' class with a static 'round' method,
this method checks if the passed value is numeric and if so it just
executes the built-in function, otherwise it returns 0. And all the
calls to 'round' in the codebase are replaced with 'NumberUtil::round'.
When rounding at subtotal is enabled, line items are already rounded where they need to, so we only should do any further rounding when displaying values and no where else.
This is part of our larger attempt to remove individual rounding as much as possible.
We were calculating subtotal to display slightly differently then we would have calculated subtotal in the cart. This was affecting subtotal value in invoices and in order confirmation screen.
This patch updates how we calculate subtotal to display such that we calculate in same way.
We added a trait to move shared logic betweem Orders and Cart. This commit refactors Order class to use that shared logic.
Also adds a test for a failing case.
`WC_Abstract_Order` and `WC_Cart_Totals` have their own logic to calculate totals. This means that we would have to fix in two places. This commit adds a trait which can be used to place shared logic between above two classes.
We were earlier rounding different tax rate values while they are merged, even if rounding at subtotal setting is enabled. This increases the rounding error, especially when prices are inclusive of taxes, and thus there is a chance that the total will be slightly different from when add the original values. For egs: https://github.com/woocommerce/woocommerce/issues/23917 .
This commit changes this behavior to round *after* we have summed all the precise unround values. Similar for items prices, we now round as late as possible, if rounding at subtotal is enabled.
* Fix for Issue #10523 - Variations ID lookup by SKU
I copied the code from the bulk() function to look up the Variation ID by the Variation SKU if the Variation ID is missing.
* Added new filter woocommerce_coupon_sort to allow plugins to override the default coupon apply order.