I’m new to WooCommerce and I have the problem that grouped products always show the default VAT because I can’t change the tax setting on the grouped products. The simple products combined by the grouped one have the reduced rate.
So I probably have to change the output in my (sub-)theme to the VAT of the first connected simple product, right?
How can I do that?
** Edit **
I have no problem with the shop calculating the VAT wrong. I have a problem with displaying the tax on grouped products. It shows the default rate with the grouped product even if all connected simple products have a reduced rate. And since I have to show the rate on the product page in germany I have to change that.
code update:
The updated code is pretty much the same, but with some new features. Like @noxoc pointed out, it would be nicer to use a hook. Above code uses the
woocommerce_grouped_product_list_before_price
action to hook in. This one is already defined insidegrouped.php
. Unfortunately this – in my mind – doesn’t read nice, because you get something like »tax information
price
«, personally I want it to read like »price
tax information
«. For that I added a actionwoocommerce_grouped_product_list_after_price
insidegrouped.php
:As you can see the new action pretty much replicates the existing one. If you added the action, you can change the
add_action()
line in above code to use it:Additionally I added some options to choose which information to show on output. You have to set the
$mode
variable for that. This should be pretty much self-explanatory – see the comment inside code. This could for example be used for setting the variable at a options page in the backend. Besides that it of course is possible to change the formatting of the output, just follow the use cases in the code do your own.code:
That would be going into the
grouped.php
located at{THEME-FOLDER}/woocommerce/single-product/add-to-cart/
inside the<td class="price">{CONTENT INSIDE}</td>
code. The code is able to distinguish betweenincluded/excluded tax
and gets according thetax rate
as well as thetax label
for the simple products inside the group.You could add a custom field to the product group eg.
tax_class
and then overwrite it with a filter in you functions.php. Example:However I’m not sure which filter would suit best. This seems a bit dirty, but should do the trick.