{"id":219,"date":"2016-11-03T12:56:40","date_gmt":"2016-11-03T12:56:40","guid":{"rendered":"http:\/\/www.3pixls.com\/blog\/?p=219"},"modified":"2016-11-03T12:57:03","modified_gmt":"2016-11-03T12:57:03","slug":"showing-prices-without-vat-based-on-roles","status":"publish","type":"post","link":"https:\/\/www.3pixls.com\/blog\/showing-prices-without-vat-based-on-roles\/","title":{"rendered":"Showing prices without VAT based on roles"},"content":{"rendered":"<p>Showing prices without VAT based on roles<br \/>\nFunction that will check for user role and turn off VAT\/tax for that role<\/p>\n<div id=\"attachment_220\" style=\"width: 310px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-220\" loading=\"lazy\" class=\"wp-image-220 size-medium\" src=\"http:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/11\/master-300x208.jpg\" alt=\"Showing prices without VAT based on roles\" width=\"300\" height=\"208\" srcset=\"https:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/11\/master-300x208.jpg 300w, https:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/11\/master-768x532.jpg 768w, https:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/11\/master-1024x709.jpg 1024w, https:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/11\/master.jpg 1656w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-220\" class=\"wp-caption-text\">Showing prices without VAT based on roles<\/p><\/div>\n<p>[php]<br \/>\nfunction wc_diff_rate_for_user() {<\/p>\n<p>\t\/\/ check for the user role<br \/>\n\tif ( is_user_logged_in() &amp;&amp; current_user_can( &#8216;wholesale_customer&#8217; ) ) {<\/p>\n<p>\t\t\/\/ set the customer object to have no VAT<br \/>\n\t\tWC()-&gt;customer-&gt;is_vat_exempt = true;<br \/>\n\t}<\/p>\n<p>}<br \/>\nadd_action( &#8216;template_redirect&#8217;, &#8216;wc_diff_rate_for_user&#8217;, 1 );<\/p>\n<p>\/**<br \/>\n * Function that filters the variable product hash based on user For more www.3pixls.com\/blog<br \/>\n *\/<br \/>\nfunction wc_get_variation_prices_hash_filter( $hash, $item, $display ) {<\/p>\n<p>\t\/\/ check for the user role<br \/>\n\tif ( is_user_logged_in() &amp;&amp; current_user_can( &#8216;wholesale_customer&#8217; ) ) {<\/p>\n<p>\t\t\/\/ clear key 2, which is where taxes are<br \/>\n\t\t$hash[&#8216;2&#8217;] = array();<br \/>\n\t}<\/p>\n<p>\t\/\/ return the hash<br \/>\n\treturn $hash;<br \/>\n}<br \/>\nadd_filter( &#8216;woocommerce_get_variation_prices_hash&#8217;, &#8216;wc_get_variation_prices_hash_filter&#8217;, 1, 3 );<\/p>\n<p>\/**<br \/>\n * Function that removes the price suffix (inc. Tax) from variable products based on role<br \/>\n *\/<br \/>\nfunction wc_get_price_suffix_filter( $price_display_suffix, $item ) {<\/p>\n<p>\t\/\/ check for the user role<br \/>\n\tif ( is_user_logged_in() &amp;&amp; current_user_can( &#8216;wholesale_customer&#8217; ) ) {<\/p>\n<p>\t\t\/\/ return blank if it matches<br \/>\n\t\treturn &#8221;;<br \/>\n\t}<\/p>\n<p>\t\/\/ return if unmatched<br \/>\n\treturn $price_display_suffix;<br \/>\n}<br \/>\nadd_filter( &#8216;woocommerce_get_price_suffix&#8217;, &#8216;wc_get_price_suffix_filter&#8217;, 10, 2 );<br \/>\n[\/php]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Showing prices without VAT based on roles Function that will check for user role and turn off VAT\/tax for that role [php] function wc_diff_rate_for_user() { \/\/ check for the user role if ( is_user_logged_in() &amp;&amp; current_user_can( &#8216;wholesale_customer&#8217; ) ) { \/\/ set the customer object to have no VAT WC()-&gt;customer-&gt;is_vat_exempt = true; } } add_action( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":220,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts\/219"}],"collection":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":2,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":222,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions\/222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/media\/220"}],"wp:attachment":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}