Last active
April 6, 2021 19:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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