Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created July 21, 2016 08:57
Show Gist options
  • Save mikejolley/5aab2ec276906bc81a21ec6584d79c2d to your computer and use it in GitHub Desktop.
Save mikejolley/5aab2ec276906bc81a21ec6584d79c2d to your computer and use it in GitHub Desktop.
WooCommerce - Hide price suffix when product is not taxable.
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_filter( 'woocommerce_get_price_suffix', 'custom_woocommerce_get_price_suffix', 10, 2 );
function custom_woocommerce_get_price_suffix( $price_display_suffix, $product ) {
if ( ! $product->is_taxable() ) {
return '';
}
return $price_display_suffix;
}
@quirinpils
Copy link

Great!

@dumlaut
Copy link

dumlaut commented Jun 8, 2018

Is there a version of this that would work to hide the price prefix if a product is taxable?

@shadowfear89
Copy link

does anyone have a version that would simply hide the price suffix when tax is simply zero? I.e. when deliver is within EU countries, website should display the suffix (i.e. incl VAT), but when a customer is outside of EU and gets prices displayed without VAT, the price suffix should be hidden.

@amityweb
Copy link

amityweb commented Jul 19, 2023

!is_taxable () does not work if you need to hide tax suffix for other reasons, like a geo located country. In the UK we show a VAT suffix but in US we would not, but because the product is still set to is_taxable when still in the US, even if tax returns as 0, the tax suffix shows. So I hide it if the tax rate is 0.

So this is what I am using, seems to work:

function custom_woocommerce_get_price_suffix( $price_display_suffix, $product )
{
	$tax = new WC_Tax(); 
	$taxes = $tax->get_rates($product->get_tax_class());
	$rates = array_shift($taxes);
	$item_rate = round(array_shift($rates));

	if ( $item_rate == 0  )
	{
		return '';
	}
	return $price_display_suffix;
}
add_filter( 'woocommerce_get_price_suffix', 'custom_woocommerce_get_price_suffix', 10, 2 );

@Rowdysign
Copy link

All code does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment