简体   繁体   中英

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM