0

I am trying to get the total shipping cost (shipping_total ) using the WC_Cart object at the checkout page.

Here is my code:

   add_action('woocommerce_cart_calculate_fees', 'add_backorder_shipping_fee', 20, 1);
   function add_backorder_shipping_fee($cart)
   {
    var_dump($cart);
   }

Here the result of the dump

   object(WC_Cart)[1005]
   .
   .
   protected 'totals' => 
    array (size=15)
      .
      .
      'shipping_total' => string '50' (length=2)
      .
      .

How can I get the shipping_total property?

I have already tried:

$cart->totals->shipping_total $cart->totals['shipping_total']

stemon
  • 599
  • 1
  • 5
  • 23

1 Answers1

0

Use this, instead:

WC()->cart->get_shipping_total()
stemon
  • 599
  • 1
  • 5
  • 23