How to add fix tax class in Woocommerce?

50 Views Asked by At

Good day! Ok so I am stuck in a special case on my website which is designed on PHP language. As everone know that on tax side you can add tax in percentage but as I my business is in California right now and currently the government is demanding to display the fixed prices on the PDF invoice that we handle to customers. And here i am badly stuck as there is literally no option on my woocommerce tax section where is can add the fixed amont as tax. Let's say i want to add 1.75$ as fixed amount per prodct sold.Also if a product sold 4 time the fixed tax mst be atomatically calculated and show the result i.e. 1.75x4=7$. Anyone here please guide me or share a code of PHP here so I can enter and achieve my desired results. Very much thankyou in advance.

1

There are 1 best solutions below

0
Yusuf Giovanno On

you can do it progrmatically using hook. action hook you can use the 'woocommerce_adjust_non_base_location_prices' hook which has 3 parameters which are ($taxes, $price, $rates)

here's an example:

add_filter('woocommerce_adjust_non_base_location_prices', 'fixed_tax_rate', 10, 3);

function fixed_tax_rate($taxes, $price, $rates) {
    //make sure the WC()->cart->tax_display_cart == 'excl' follow your custom tax name
    if (function_exists('WC') && WC()->cart && WC()->cart->tax_display_cart == 'excl') {
        //put your logic here
        $custom_tax_rate = 10;
        $taxes['custom_tax_rate'] = ($price / 100) * $custom_tax_rate;
    }
    return $taxes;
}

you can put this in your functions.php in your theme folder