• Resolved SallyLynnMacDonald

    (@sallylynnmacdonald)


    I have placed the following code in the functions.php… and I can see that the tax rate is calculated as it should for the four states that we need to apply sales tax to; BUT I cannot charge a wholesale customer sales tax – and so I created a zero rate entry and used this code to capture the ‘wholesaler’ role as well as ‘administrator for testing. I’m still getting charged sales tax. Help please.

    /**
     * Apply a different tax rate based on the user role.
     *
     * @param $tax_class
     * @param $product
     *
     * @return string
     */
    function woo_diff_rate_for_user( $tax_class, $product ) {
    
        $current_user = wp_get_current_user();
        $roles = $current_user->roles;
        $current_user_role = $roles[0];
    
        $not_taxed_roles = array("wholesale", "administrator");
    
        if (is_user_logged_in() && in_array($current_user_role, $not_taxed_roles)) {
    
            $tax_class = "Zero Rate";
        }
        return $tax_class;
    }
    add_filter( "woocommerce_product_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
    add_filter( "woocommerce_product_variation_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need Zero Rate Tax based on wholesale user role’ is closed to new replies.