0

I have The WC()->cart object that has this structure:

object(WC_Cart)#803 (13) {
  ["cart_contents"]=>
  array(3) {
    ["e369853df766fa44e1ed0ff613f563bd"]=>
    array(11) {
      ["key"]=>
      string(32) "e369853df766fa44e1ed0ff613f563bd"
      ["product_id"]=>
      int(34)
      ["variation_id"]=>
      int(0)
      ["variation"]=>
      array(0) {
      }
      ["quantity"]=>
      int(1)
      ["line_tax_data"]=>
      array(2) {
        ["subtotal"]=>
        array(1) {
          [1]=>
          float(31.5)
        }
        ["total"]=>
        array(1) {
          [1]=>
          float(31.5)
        }
      }
      ["line_subtotal"]=>
      float(150)
      ["line_subtotal_tax"]=>
      float(31.5)
      ["line_total"]=>
      float(150)
      ["line_tax"]=>
      float(31.5)
      ["data"]=>
      object(WC_Product_Simple)#1251 (12) {

After WC()->cart->cart_contents I don't know how to get 'line_subtotal' value.

May I need to convert this object to something else before trying to get any value?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Tautve
  • 59
  • 8

1 Answers1

1

Try this.

foreach(WC()->cart->cart_contents as $cart_content) {
    echo $cart_content['line_subtotal']
}

using foreach since the value of "cart_contents" is array.

Aljay
  • 456
  • 7
  • 21