WooCommerce shipping discount - php

I have a client that set up a site with WooCommerce and are processing tax exempt customers with a coupon code. The coupon applies a discount to amount using the same percentage as the sales tax essentially offsetting the amount.
the problem I have is they are also charging sales tax on shipping. The coupon will apply the discount to the items in the cart but not shipping. I need to make sure a discount is applied to shipping to offset the tax there is well.
This is my first time looking under the hood of WooCommerce and could use some advice.
My first step has been to start with the woocommerce_before_cart_table hook to get applied coupons and totals. Just not sure were to go from there.
Again, any advice is greatly appreciated.
I should also point out there is no budget or time to go in and do a full tax exemption plugin. (Although I believe I may when I have time)

Filter the shipping rates and remove the taxes for tax exempt buyers.
add_filter( 'woocommerce_package_rates', 'filter_rates_to_remove_taxes', 10, 2 );
public function filter_rates_to_remove_taxes( $rates, $package ) {
// if buyer is tax exempt remove taxes from rates //
return $rates;
}
And do tell client to pay for your services, he surely is out to make money with the site and you should treat this professionaly.

Related

Apply coupon after calculate the shipping rate - woocommerce

I am building my website by using woocommerce, but i faced the problem of calculating the total amount of the order.
There is a shipping method which is 15% additional fee of the order, and there is a coupon offers $10 discount.
But woocommerce seems like apply the coupon before calculate shipping fee.
For example, the order total amount is $100, the expected result should be (100*1.15) - 10 = 105, but when i tested in the checkout page, the total amount is (100-10) * 1.15 = 103.5.
May I know how to apply the coupon after calculate the shipping fee?
Thank you.
I want to calculate amount correctly in woocommerce, which is apply coupon after calculate the shipping fee.

WooCommerce Inclusive Tax for International Orders

I use the API to set the prices on my site and its configured to accept inclusive prices.
I have set up the standard rate for the VAT for my country.
I now need to allow a neighbouring country to be able to purchase from my store. However, I want them to buy at the inclusive price but with no VAT.
I tried adding the country to the standard rates at 0% but that just deducts the local VAT from the price. So if the price is $15 normally, now will show as $12. I need the price to be the same as the local inclusive price but with 0% VAT.
So if I sell something for $15, the VAT may be $3 locally. On my local orders this what will show. Now if my foreign customer wants to buy something, it need to still show it at $15 but the VAT is 0%.
I just can't find a way to get the system configured that way.
Found the answer
add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false' );

How to make cart & checkout page calculation in opencart

Actually, i'm working on opencart 2.3, if now checkout page calculation in opencart:
Sub-Total₹ 1,520.00
India Shipping₹ 180.00
Discount (-07%)₹ -119.00
Total₹ 1,581.00
it s taking discount in shipping amount also i don't want discount shipping amount, i want calculation like this please help.
Sub-Total₹ 1,520.00
Discount (-07%)₹ -106.40
India Shipping₹ 180.00
Total₹ 1,593.60
you should change in admin>extensions>extensions>Order totals... sort order for the shipping. Move it down by changing sort order number higher than your discount voucher.

WooCommerce shipping price INCLUSIVE tax

In WooCommerce I can only enter the shipping price excluding tax.
How can I make the given price including tax?
The settings to show 'prices including tax' only applies to the products.
So for example if I enter in the settings shipping €1,00
It shows on the checkout €1,21 (0,21 = tax)
It should be €1,00 (incl. 0,21 tax)
(Don't care about the calculation here, it's just an example)
Thanks if anybody has a solution or function for this.
A year after the original question I just hit the same problem and there is not a lot out there to help.
On investigation this turns out to be a problem with the shipping tax calculation from "class-wc-tax.php" which as you can see below hard codes shipping to be tax exclusive.
/**
* Calculate the shipping tax using a passed array of rates.
*
* #param float Price
* #param array Taxation Rate
* #return array
*/
public static function calc_shipping_tax( $price, $rates ) {
$taxes = self::calc_exclusive_tax( $price, $rates );
return apply_filters( 'woocommerce_calc_shipping_tax', $taxes, $price, $rates );
}
It turns out that for some reason that woo have pushed this assumption of shipping being tax exclusive through their down stream tax calculations so you will need to add a couple of filters to your functions.php in order to fix things.
1) The first to calculate the inclusive tax
function yourname_fix_shipping_tax( $taxes, $price, $rates) {
if(wc_prices_include_tax()){
return WC_Tax::calc_inclusive_tax( $price, $rates );
}
return $taxes;
}
add_filter( 'woocommerce_calc_shipping_tax', 'yourname_fix_shipping_tax',10,3);
Careful that you don't forget the 10,3 at the end of add_filter. The 10 is the priority which I have left at the default. The 3 is the number of arguments. You really need this one - the filter displays behavioral problems if you leave it out.
2) The second filter is to fix the totals in downstream calculations.
function yourname_fix_totals( $cart) {
if(wc_prices_include_tax()){
$cart->shipping_total -= $cart->shipping_tax_total;
}
}
add_filter( 'woocommerce_calculate_totals', 'yourname_fix_totals');
Detail for those that worry that this is real money and real taxes we are talking about
The first filter is fairly straight forward - it simply recalculates the tax in the inclusive case.
The second filter is to deal with woo pushing the assumption of exclusive tax further into their tax calculations.
Around line 1396 of 'class-wc-cart.php' we have the following.
// Grand Total - Discounted product prices, discounted tax, shipping cost + tax
$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp ), $this ) );
What this wants to do is add the shipping tax to the shipping total which we don't want it to do - and they have hard coded it in......
What we will do is use the conveniently located 'woocommerce_calculate_totals' filter() a few lines above around line 1392 to subtract the shipping tax from the total before it all gets added up using the second filter above.
// Allow plugins to hook and alter totals before final total is calculated
do_action( 'woocommerce_calculate_totals', $this );
In an earlier cut of this post from a few weeks back I was worried that this would be a can of worms - and it is turning out to be just that now that I can test things.
So huge caveat here. Test your final tax totals and subtotals thoroughly - this is no longer possibly a risk. Woo have made the assumption of tax exclusive shipping and have pushed it through their downstream calculations. Unfortunately you will have to pay tax to your respective governments even if there was a bug in you code.
Remember also when testing that when you change from exclusive to inclusive taxes in woocommerce settings that old prices are not affected, so you may need to use clean test data.
With all that said so far it is looking ok for me, but in my scenario I am bypassing large amounts of woo - I am not using any of their front end code which means I may not have found other places impacted by the assumption of tax exclusive shipping.
A possible alternative solution is to manually adjust the pricing for shipping so it becomes VAT exclusive. I.e. if shipping incl 20% tax is 6 EUR, adjust it to 5 EUR. Note that this only works if your tax rate is the same for all shipping destinations.

Magento calculate shipping to be refunded on partial refund

I'm trying to figure out how to calculate the shipping refund on orders where some of the items are being refunded. Currently, in the credit memo screen, the amount in the input field is the total amount paid for shipping. When you adjust the quantity of items being refunded, and hit update, the shipping refunded amounts stays the same. I'd like to adjust it to be the portion of shipping that is related to the items being refunded.
As a calculation, I was thinking this would be:
total shipping cost - new calculation of shipping for items not being refunded = shipping cost of items being refunded.
I can see that the calculation for shipping is done in this class:
Mage_Sales_Model_Order_Creditmemo_Total_Shipping
However, I am having trouble figuring out how I would rerun the shipping calculation for the credit memo items.
Anyone have any thoughts on how I might be able to accomplish this?

Categories