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.
Related
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.
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']).
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!
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.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I allow users to enter prices of products into an inventory, in either NET or Gross. If they enter the price in Gross, the NET is computed for them before being stored and uses the following code:
var vatrate = 12;
IsuppGross = parseInt(suppGross * 100); // makes it an integer
// calc net
var revVR = parseFloat('1.'+vatrate);
Net = ( ( IsuppGross / revVR) / 100 ).toFixed(2);
I struggled to get that working and am not sure if that is where the problem lies.
If I enter '100.00' as a gross figure and my VAT rate is 12%, it returns Net as '112.00', so it seems to be working.
So I enter a product with a Gross price of $100.00 and the net price is computed to be '$89.29' (which I'm assuming to right).
When creating an invoice for 10 of the above items, the bottom of the invoice looks like this:
Net Subtotal $892.90
VAT $107.15
Grand Total $1000.05
What I am expecting is:
Net Subtotal $892.90
VAT $107.10
Grand Total $1000.00
...especially since, when selling just one of the above, results in:
Net Subtotal $89.29
VAT $10.71
Grand Total $100.00
...which expected. It would therefore be reasonable to assume that purchasing 10 of the same items, would cost exactly ten times as much.
Here is the formula I'm using to add the VAT to the Net subtotal:
quantity x net price x 0.12 (10 x 89.29 x 0.12) = 107.148
The above then rounds to 107.15 which when added to the net subtotal is 1000.05.
What formula do I need to arrive at 1000 when I add the VAT back on please?
To Summarize / Clarify
This formula...
quantity x net price x 0.12 (10 x 89.29 x 0.12)
Gives me 107.148, but what I think I need it to give me is 107.10 instead.
So what javascript function can I used to make that happen (or how do I need to adjust my formula / convert it to code)?
UPDATE
#jakub is on the right track I think. I've found an easy way to test it by doing something like:
alert( (892.90 * 0.12).toFixed(2) ); // should equal 107.10
(still equals 107.15)
The above was based on input from Jakub, below. Notice that I'm not multiplying by 10 separately here, because I noticed that we're working at the subtotal level.
One way to do that would be to put rounding at a different place
round(quantity * price) != quantity * round(price)
The same goes for VAT, rounding the result is slightly different from rounding VAT from one product and then multiplying by quantity. Also, you know, that quantity has to be an integer, not a float (if not, it is a different case), so multiplying after rounding should never produce more decimal places.
I hope this helps a little bit.
Ok, to respond to your edit:
You have
(quantity * price * VAT).toFixed(2) = (10 * 89.29 * 0.12).toFixed(2) = (107.148).toFixed(2) = 107.15
You should have
quantity * (price * VAT).toFixed(2) = 10 * (89.29 * 0.12).toFixed(2) = 10 * (10.7148).toFixed(2) = 10 * 10.71 = 107.10
I think I'm correct in saying that the legal position is that the VAT amount invoiced must be the correct percentage of the goods & services invoiced, so one should not sum the VAT-inclusive line-item prices.
One system I worked on which showed VAT per line modified the last line's VAT amount to eliminate rounding errors. They will always be there unless you show your prices with 5 decimal places (assuming you have a VAT rate with 3 significant digits).
Basically the reason for this issue is that the computer is not able to represent most base 10 real numbers using floating point numbers, since the computer uses base 2.
Check this thread:
Why not use Double or Float to represent currency?
So one first step is to always use integers for the currency, in this case measured in cents instead of dollars, I presume.