Woocommerce round the tax rate - php

I am trying to add a specific fixed tax to a product. So i found a solution which it worked for me.
Problem is that I want a 4.7% tax, but its round up to 5%.
The tax in woocommerce is using a 4 decimal rate: Rate %: 4.7000.
Any fixes for this one?

If i understand you correctly, you can use round() with second parameter of "The optional number of decimal digits to round to. " Checkout https://www.php.net/manual/en/function.round.php

If anyone return to this question:
under your activated theme: review-order.php, is printing the tax rounding up.
echo sprintf('%.0f%%', $tax_rate['rate']).
You can change the value to 1 or 2 to get the decimal number.
So for me it was: echo sprintf('%.1f%%', $tax_rate['rate']).

Related

Filter Item Unit Price when Order is Created in WooCommerce

I'm using Zapier to export orders from WooCommerce to my account software when an order is created. The data is sent via WooCommerce REST API.
Everything works fine but I noticed that the unit price in the order meta data sometimes displays product prices with more than 2 decimal places. This happens when more than one of the same item is ordered. It seems to always happen when the item price has two decimal places and is ordered in multiples of odd numbers.
My accounting software only accepts up to 2 decimal places. So there is an error every time the unit price has more than two decimal places. This is how I discovered this issue.
I have checked the item price and the prices are correct. I also tested by enabling and disabling "Round tax at subtotal level, instead of rounding per line". Nothing seems to resolve the issue.
I would like to filter the unit price when an order is generated in WooCommerce so that they are converted to two decimal places. Any thoughts or suggestions on how to go about resolving this would be appreciated.
Here is an example of just one order where the item is displaying with more than 2 decimal places:
isCreditInvoice:false
customer:d58ca99b-07f3-45fa-80ae-164ebbc881f1
invoiceDate:2021-03-07T09:18:06+02:00
quantity:1,1,1,1,1,1,2,6,6,5,7,7,4,10,10,1,1,1,1,1,1,1,1
yourReference:Order Number 6631
deliveryDate:{{111079934__date_completed}}
ourReference:Order Number 6631
unitPrice:22.5,22.5,26.25,25,34.95,34.95,23.76,6.95,6.95,6.95,9.950000000000001,9.950000000000001,9.95,1.6,1.6,14.95,23.4,8.4,30,21.36,25,12.5,26.5
Update: This is a WooCommerce Plugin Core issue and has already been reported to WooCommerce on Github
https://github.com/woocommerce/woocommerce/issues/27911
Use the following patch to temporarily fix the issue:
Navigate to line 172 of woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php
Replace:
$data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0;
With:
$data['price'] = $item->get_quantity() ? wc_format_decimal( $item->get_total() / $item->get_quantity() ): 0;
Tested and works.
Now the unitPrice will be rounded to two decimal places.

WooCommerce Points and Rewards and discount rounds up

I am using WooCommerce Points and Rewards plugin. The issue I have is when applying points to cart, it is rounding up to the nearest integer. I would like for it to apply in cents.
For example: 10 points = 1 dollar. If customer has 11 points so the discount should be $1.10, but not $2.00. I've looked through the plugin code but do not see where this is being force to round up.
Any advise or thoughts?
This plugin round the points on the displayed cart notice… You can't apply in cents… You can only tune in the plugin settings the "Earn Points Rounding Mode" and the best round mode is: "Round to nearest integer"…
What you can do is to fix a minimal number of points to get the discount and display the related notice with the folowing code (Fixed to 100 points below):
// Points and rewards conditional redeem points message display up to 100 points
add_filter( 'wc_points_rewards_redeem_points_message', 'conditional_redeem_points_message', 10, 2 );
function conditional_redeem_points_message( $message, $discount_available ){
$points = WC_Points_Rewards_Manager::calculate_points_for_discount( $discount_available );
if( $points >= 100 )
return $message;
else
return '';
}
And in the plugin settings you will Fix the same number for "Maximum Points Discount".
So the notice will be displayed only for this minimal number of points and the available cart discount will be a real corresponding integer amount…
I haven't find already another way.

Woocommerce Tax calculating issues (wrong price amount per line)

WooCommerce calculates the VAT (in this case 20%) per line (wrong), but really should calculate VAT per item (right).
For example, we have a product that is 0.13p (excl VAT), which shows as 0.16p (inc VAT) on the frontend. This is fine as 0.13p + 20% = 0.156p and is rounded up to 0.16p. If you add 5 of these to the cart you would expect to see 0.16p x 5 = 0.80p but instead we get 0.78p. My guess is that WooCommerce is calculating the VAT per line and not per item (e.g. 0.13p x 5 = 0.65p and then 0.65p + 20% = 0.78p). See below.Wrong Amount
I have tried all sorts of different settings with no success, this is how they are now (see pic attached).Tax Settings
Has anyone experienced the same issue? Have you found a solution? Obviously, I can't launch this with such a bug.. Many thanks!

Woocommerce Shipping Calcuation (%) wrong

On my Woocommerce shop I have a percentage based shipping cost. The percentage is set to 5 ([fee percent="5"]) which returns a wrong calculation, but interestingly enough it seems to be the separator that is placed wrong (see attached example). 5% in the example is 14.5 GBP, but Woocommerce returns the calculation as 1.45.
Any suggestions?
THANKS

Magento 3 decimals when ordering products in backend

When creating a product in magento catalog we have 3 decimals but when they are added to a order they become 2 and lose the 3rd number, leaving the price rounding up to a wrong number and adding a cent to the price.
For example 350.00 EUR becomes 350.01 EUR when added to cart then this shows up every where.
The VAT is 21 percent and we tried changing how VAT works (per item, per line, per cart) but it works on some producs but not all.
We atleast need to find how to make 3 decimals when creating an order on the product list, this way we could fix some of the problem.
Preview:
Need 3 decimals in the custom price input:
http://i.stack.imgur.com/yP5tl.jpg
Thanks and bye!
You don't have to change any database fields, magento by default supports working with prices up to 4 decimals precision, but it does by default work with a precision of 2.
In order to force magento make all calculations in cart/checkout/order with a precision of 3 you must override Mage_Core_Model_Store::roundPrice() like below
function roundPrice($price)
{
return round($price, 3);
}
For displaying purposes (if you want also visually to see prices with 3 decimals) you must override Mage_Directory_Model_Currency::format() like below
public function format($price, $options = array(), $includeContainer = true, $addBrackets = false)
{
return $this->formatPrecision($price, 3, $options, $includeContainer, $addBrackets);
}
Also please note that the rounding issue are a well known problem by magento, even if you change the precision and your example may work fine(you wouldn't see the extra .01), other situations may break. Magento posted some recommedations & best practices on how to setup taxes to minimize this issue.
I also had same issue.I made change in database in price field.Please check in database for field datatype. Make it decimal(10,3) or decimal. I hope it will solve your problem.

Categories