• Resolved JJ Montalban

    (@jjmontalban)


    Hi

    How Can I apply different taxes in a determinated product category depending a role user? For example:

    – Professional Role user:

    21% tax in Category A
    10% tax in Category B
    5% tax in rest of categories

    – Distribuitor Role user:

    10% tax in category A
    0% tax in category B
    21% tax in rest of categories

    Right now I have created product price without taxes .I apply different taxes based on role user like this:

    add_filter( 'woocommerce_before_cart_contents', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_before_shipping_calculator', 'wc_diff_rate_for_user', 1, 2);
    add_filter( 'woocommerce_before_checkout_billing_form', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );
    function wc_diff_rate_for_user( $tax_class ) {
    
        if ( current_user_can( 'some role user' ) ) {
            $tax_class = 'some tax';
        }
        return $tax_class;
    }

    But I dont know how apply taxes depending of product category. Its possible?

    Thanks in advanced

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter JJ Montalban

    (@jjmontalban)

    If somebody need:

    add_filter( 'woocommerce_before_cart_contents', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_before_shipping_calculator', 'wc_diff_rate_for_user', 1, 2);
    add_filter( 'woocommerce_before_checkout_billing_form', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 1, 2 );
    
    function wc_diff_rate_for_user( $tax_class, $product ) {
    
        if ( current_user_can( 'user role 1' ) ) {
            if ( has_term( array('category A', 79), 'product_cat', $product->get_id() ) ) {
    			$tax_class = 'Tax 1';
    		}
        }
    
    	if ( current_user_can( 'user role 2' ) ) {
            if ( has_term( array('category B', 79), 'product_cat', $product->get_id() ) ) {
    			$tax_class = 'Tax 2';
    		}
        }
    
        return $tax_class;
    }

    Caution: woocommerce_product_tax_class is deprecated

    Plugin Support B C. a11n

    (@battouly)

    Hi there,

    `Within the free WooCommerce plugin, there is no functionality that would allow for the configuration of different tax rates based on a WordPress user role.

    Researching on Google I did find some possible code solutions which you could investigate further though.

    https://www.google.com/search?q=WooCommerce+tax+rate+by+user+role

    For the custom codes, I am not able to help with it, but I will leave the topic unresolved for further discussion with other forums members.

    Thanks!

    Thread Starter JJ Montalban

    (@jjmontalban)

    Hi

    Thanks for the info. But no exists any free plugin about this. Although my last code works correctly.

    Best regards.

    add_filter( 'woocommerce_before_cart_contents', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_before_shipping_calculator', 'wc_diff_rate_for_user', 1, 2);
    add_filter( 'woocommerce_before_checkout_billing_form', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 1, 2 );
    add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 1, 2 );
    
    function wc_diff_rate_for_user( $tax_class, $product ) {
    
        if ( current_user_can( 'user role 1' ) ) {
            if ( has_term( array('category A', 79), 'product_cat', $product->get_id() ) ) {
    			$tax_class = 'Tax 1';
    		}
        }
    
    	if ( current_user_can( 'user role 2' ) ) {
            if ( has_term( array('category B', 79), 'product_cat', $product->get_id() ) ) {
    			$tax_class = 'Tax 2';
    		}
        }
    
        return $tax_class;
    }
    mother.of.code

    (@imazed)

    The Mother of Code

    Hey @jjmontalban – thanks for sharing that! We’ll consider this topic as resolved. You may want to release this as a mini plugin, if you have the time to maintain it ?? Happy selling!

    Thread Starter JJ Montalban

    (@jjmontalban)

    may be now is the moment of publish my first plugin…

    Margaret S. woo-hc

    (@margaretwporg)

    Cheers! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Different product category taxes based on role user’ is closed to new replies.