Get woocommerce carts total amount

前端 未结 12 1798
北恋
北恋 2020-12-30 23:33

I am trying to apply a discount to a carts total price, but I can only do it to the item base price and not the over all price. I Googled and came across this post in the w

12条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 00:32

    Function get_cart_contents_total() gives the total of items in the cart, but after discounts. Depending on the tax settings you might have to add taxes. Something lie this:

    $cart_total_price = wc_prices_include_tax() ? WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax() : WC()->cart->get_cart_contents_total();
    

提交回复
热议问题