roles ) ) {
foreach ( array_keys( $taxes ) as $key ) {
$taxes[$key] = 0;
}
}
return $taxes;
}, 100, 2 );
/**
* Part 2: Display the message on the CART page (Server-side PHP)
* This works perfectly for the non-dynamic cart page.
*/
add_action( 'woocommerce_cart_totals_before_order_total', function() {
if ( is_user_logged_in() && in_array( 'tax_exempt_customer', (array) wp_get_current_user()->roles ) ) {
echo '
Tax Exempt
$0.00
';
}
});
/**
* Part 3: Display the message on the CHECKOUT page (Client-side JavaScript)
* This handles the AJAX updates on the dynamic checkout page.
*/
add_action( 'wp_footer', function() {
// Only run this script for exempt users and only on the checkout page.
if ( is_checkout() && ! is_wc_endpoint_url() && is_user_logged_in() && in_array( 'tax_exempt_customer', (array) wp_get_current_user()->roles ) ) {
?>
Skip to content