eylul
eylul

Reputation: 101

Woocommerce Mini Cart - How to show prices excluding tax

my woocommerce mini cart shows the product price including tax by default. (the prices are shown excluding the tax all over the website) I'd like to show the prices excluding tax on mini cart, but keep showing them including tax in the main cart page. I believe it can be achieved with a hook but I wasn't able to do it. Any help would be very much appreciated.

Upvotes: 1

Views: 2382

Answers (1)

Thai Duong Tran
Thai Duong Tran

Reputation: 2522

Woocommerce provides two function wc_get_price_excluding_tax and wc_get_price_including_tax that you can use to display the product with or without tax.

What you might need to do is update your cart template file to use wc_get_price_excluding_tax to display the item price.

You can look at how these functions are implemented here: https://docs.woocommerce.com/wc-apidocs/function-wc_get_price_including_tax.html.

One thing to note that these function take a WC_Product object product as their first parameter, so you might need to get the product from the cart item first. You can do it by using wc_get_product. An example:

foreach( WC()->cart->get_cart() as $cart_item ){
    $product_id = $cart_item['product_id'];

    $product = wc_get_product($product_id);

    // Display the price here
    echo wc_get_price_excluding_tax($product);
}

Upvotes: 2

Related Questions