Randy Hall
Randy Hall

Reputation: 8167

Shipping cost not showing in cart total - WooCommerce

I have a custom API endpoint that triggers processing shipping costs using a custom class.

That works fine.

I add my rate by running the normal calculate function:

WC()->cart->calculate_shipping();

I see the rate being added:

//... bunch of code to calculate cost
//... what it actually does here is irrelevant
$rate = array(
    'id' => $this->id,
    'label' => $this->title,
    'cost' => $cost
);

$this->add_rate( $rate );
echo "added rate at $cost";
//prints: "added rate at 10"

I can return the expected shipping cost in my API method or on the page itself:

echo WC()->cart->get_cart_shipping_total();

<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>10.00</span>

But when I get the cart and cart total, there's the total for my test item but no shipping to be found. Item cost is $30, shipping as we've seen is $10:

<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>30.00</span>

Am I wrong thinking that get_cart and get_cart_total should return the shipping cost?

Any help with how to further debug or theories to test are welcome.

Upvotes: 3

Views: 4815

Answers (1)

Randy Hall
Randy Hall

Reputation: 8167

Finally figured it out, one of those it's so easy I can't believe I didn't figure it out sooner type of things.

This only gets the cart total:

WC()->cart->get_cart_total();

This gets the entire total for the order:

WC()->cart->get_total();

Upvotes: 7

Related Questions