• Resolved jimbo777

    (@jimbo777)


    Hi,

    I am using your plugin which works great. Now I created a new user role called: “Dealer” and I am trying to tax exempt all users which have the dealer role.

    I am using the code found below and have already inserted my Dealer role and placed code in functions.php : https://gist.github.com/kloon/5948116

    // Place the following code in your theme’s functions.php file and replace tax_exempt_role with the name of the role to apply to

    add_action( ‘init’, ‘woocommerce_customer_tax_exempt’ );
    function woocommerce_customer_tax_exempt() {
    global $woocommerce;
    if ( is_user_logged_in() ) {
    $tax_exempt = current_user_can( ‘dealer’);
    $woocommerce->customer->set_is_vat_exempt( $tax_exempt );
    }
    }

    I tried multiple times, unfortunately, tax still remains.
    Next, I also created a Zero Tax rate in WooCommerce and tried this code:

    /* No tax for dealer */
    function zero_rate_for_custom_user_role( $tax_class, $product ) {
    // Getting the current user
    $current_user = wp_get_current_user();
    $current_user_data = get_userdata($current_user->ID);

    // <== <== <== <== <== <== <== Here you put your user role slug
    if ( in_array( ‘dealer’, $current_user_data->roles ) )
    $tax_class = ‘Zero Rate’;

    return $tax_class;
    }
    add_filter( ‘woocommerce_product_get_tax_class’, ‘wc_diff_rate_for_user’, 10, 2 );
    add_filter( ‘woocommerce_product_variation_get_tax_class’, ‘wc_diff_rate_for_user’, 10, 2 );

    This didn’t work either. I am not sure why this isn’t working. Could someone look at the codes above or maybe even paste a different snippet here which may work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jimbo777

    (@jimbo777)

    I solved this issue. I have another question: Does this Plugin have a “Guest” or “Visitor” status for people who have not created account yet or logged in?

    I only see “Customers” in roles.

    Plugin Author Caseproof

    (@caseproof)

    Hi @jimbo777

    When visitors are not logged in, they don’t have any roles and I’m afraid it’s not possible to assign any role to these users. In that case, you can only check if the user is logged in using is_user_logged_in() function.

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Tax Exempt Role’ is closed to new replies.