Get woocommerce carts total amount

前端 未结 12 1778
北恋
北恋 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:20

    As of late 2018, the best way is to use get_cart_contents_total(). This is the total of items in the cart after discounts.

    WC()->cart->get_cart_contents_total(); // Float
    

    Other methods are available for more specific needs, just have a look at the docs.

    0 讨论(0)
  • 2020-12-31 00:25
    WC()->cart->subtotal; 
    this function use for get total without currency
    WC()->cart->get_total();
    this function use for get total with currency
    
    0 讨论(0)
  • 2020-12-31 00:26

    This also work nicelly.

    WC()->cart->total

    0 讨论(0)
  • 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();
    
    0 讨论(0)
  • 2020-12-31 00:36

    This works perfectly and removes currency symbol:

         $woocommerce->cart->total;
    
    0 讨论(0)
  • 2020-12-31 00:38

    The following code outputs formatted price with currency

    wc_price( WC()->cart->cart_contents_total); // Output example $118,000
    
    0 讨论(0)
提交回复
热议问题