Untitled
unknown
plain_text
3 months ago
1.1 kB
8
Indexable
add_filter('woocommerce_product_get_tax_class', 'customize_tax_class_based_on_user_type', 10, 2); add_filter('woocommerce_product_variation_get_tax_class', 'customize_tax_class_based_on_user_type', 10, 2); function customize_tax_class_based_on_user_type($tax_class, $product) { // Get current user ID $user_id = get_current_user_id(); // Check if user is B2B $is_b2b = get_user_meta($user_id, 'b2bking_b2buser', true) === 'yes'; // If not B2B (i.e., B2C), adjust the tax calculation if (!$is_b2b) { // This filter will run when calculating ICMS tax add_filter('woocommerce_calculate_tax', 'remove_icms_for_b2c', 10, 5); } return $tax_class; } function remove_icms_for_b2c($taxes, $price, $rates, $price_includes_tax, $suppress_rounding) { foreach ($rates as $key => $rate) { // Check if this is the ICMS tax if (strpos($rate->tax_rate_name, 'ICMS') !== false) { // Set ICMS tax to 0 for B2C $taxes[$key] = 0; } } return $taxes; }
Editor is loading...
Leave a Comment