Created
November 26, 2021 15:23
-
-
Save jjmontalban/3ff580810f950eb255b69e449c5c8050 to your computer and use it in GitHub Desktop.
aplica una tasa a una categoria de producto dependiendo del rol de usuario
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Override WooCommerce tax display option for distributors. | |
* | |
* @see http://stackoverflow.com/questions/29649963/displaying-taxes-in-woocommerce-by-user-role | |
* @see https://www.businessbloomer.com/woocommerce-check-if-products-belongs-to-category-tag/ | |
*/ | |
add_filter( 'woocommerce_before_cart_contents', 'tax_category_role', 1, 2 ); | |
add_filter( 'woocommerce_before_shipping_calculator', 'tax_category_role', 1, 2); | |
add_filter( 'woocommerce_before_checkout_billing_form', 'tax_category_role', 1, 2 ); | |
add_filter( 'woocommerce_product_get_tax_class', 'tax_category_role', 1, 2 ); | |
add_filter( 'woocommerce_product_variation_get_tax_class', 'tax_category_role', 1, 2 ); | |
function tax_category_role( $tax_class ) { | |
if ( current_user_can( 'passive' ) ) { | |
global $product; | |
$product_id = $product->get_id(); | |
if ( has_term( 'portatiles', 'product_cat', $product_id ) ) { | |
$tax_class = 'Zero Rate'; | |
} | |
} | |
return $tax_class; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment