Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save webdados/be0a8a18859051281ba751d2b6662b23 to your computer and use it in GitHub Desktop.
Save webdados/be0a8a18859051281ba751d2b6662b23 to your computer and use it in GitHub Desktop.
Show WooCommerce prices with or without tax / VAT depending on user profile / option
<?php
/* WooCommerce prices shown with or without tax depending on client type */
add_filter( 'option_woocommerce_tax_display_shop', 'woocommerce_show_prices_with_or_without_tax' );
add_filter( 'option_woocommerce_tax_display_cart', 'woocommerce_show_prices_with_or_without_tax' );
function woocommerce_show_prices_with_or_without_tax( $option ) {
if ( is_user_logged_in() ) {
//Client type from user_meta or profile or whatever...
//Example: $client_hide_tax = get_user_meta( get_current_user_id(), 'client_type', true ) ? true : false;
//Example to create this field on registration: https://gist.github.com/webdados/c8dbbe7ccdea3463312e5b865ad92d92
$client_hide_tax = true;
return $client_hide_tax ? 'excl' : $option;
} else {
/* Assumes "Display prices in the shop" and "Display prices during cart and checkout" is set to "Including tax" in WooCommerce > Settings > Tax */
return $option;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment