Skip to content

Instantly share code, notes, and snippets.

@opicron
Last active October 20, 2022 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opicron/a123dcfba6259410259a9481f5d65d9d to your computer and use it in GitHub Desktop.
Save opicron/a123dcfba6259410259a9481f5d65d9d to your computer and use it in GitHub Desktop.
Tax - exempt guests and customers #php #woocommerce
<?php
/**
* Function that will check for user role and turn off VAT/tax for that role
*/
function wc_diff_rate_for_user() {
// check for the user role
if ( ! is_user_logged_in() || current_user_can( 'customer' ) ) {
// set the customer object to have no VAT
WC()->customer->set_is_vat_exempt( true );
}
}
add_action( 'template_redirect', 'wc_diff_rate_for_user', 1 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment