Hide additional excluding tax price if product is not taxable in Woocommerce Hide additional excluding tax price if product is not taxable in Woocommerce wordpress wordpress

Hide additional excluding tax price if product is not taxable in Woocommerce


First woocommerce_price() function and get_price_excluding_tax() method are deprecated and outdatedā€¦ They are replaced by wc_price() and wc_get_price_excluding_tax() functions.

Instead of overriding woocommerce template loop/pride.php you could use the following code to achieve what you want with this hooked custom function:

add_action( 'woocommerce_after_shop_loop_item_title', 'conditionally_add_price_excluding_vat ');function conditionally_add_price_excluding_vat(){    global $product;    if( $product->get_tax_status() != 'taxable' ){        $price_excl_vat = wc_get_price_excluding_tax($product);        echo'<p class="netto">'.wc_price($price_excl_vat).' '. __('netto').'</p>';    }}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and works.

The additional "netto" price will be hidden when the product "Tax status" is set to "None" on product archive pages.


I haven't tested it yet but I expect something like this should be working:

add_action('woocommerce_before_shop_loop_item','custom_remove_loop_price');function custom_remove_loop_price(){    global $product;    if(!$product->price){        remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price',10);    }}


<p class="netto"></p><?php ($product->get_price_excluding_tax() != null) ? echo woocommerce_price($product->get_price_excluding_tax()) : echo 0; ?> netto</p>