在 Woocommerce 中获取购物车运输标签和成本 [英] Get the Cart shipping label and cost in Woocommerce

查看:28
本文介绍了在 Woocommerce 中获取购物车运输标签和成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在购物车页面的另一侧显示运费.

I need to display the shipping cost in other side of cart page.

我试过了:

<?php
$current_shipping_cost = WC()->cart->get_cart_shipping_total();
echo $current_shipping_cost;
?>

但是打印价值和运费的标题不一样,因为我用作标题:使用 UPS 24/48 小时快递 4.90 欧元"...

But print value nad don't title of shipping cost, because i use as title: "Express delivery with UPS 24/48 hours 4.90 euro"…

如何在 woocommerce 中获取订单运费?

How can I get order shipping cost in woocommerce?

推荐答案

要在购物车页面 (或在结帐页面):

foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){
    if( WC()->session->get('chosen_shipping_methods')[0] == $method_id ){
        $rate_label = $rate->label; // The shipping method label name
        $rate_cost_excl_tax = floatval($rate->cost); // The cost excluding tax
        // The taxes cost
        $rate_taxes = 0;
        foreach ($rate->taxes as $rate_tax)
            $rate_taxes += floatval($rate_tax);
        // The cost including tax
        $rate_cost_incl_tax = $rate_cost_excl_tax + $rate_taxes;

        echo '<p class="shipping-total">
            <strong class="label">'.$rate_label.': </strong>
            <span class="totals">'. WC()->cart->get_cart_shipping_total() .'</span>
        </p>';
        break;
    }
}

这篇关于在 Woocommerce 中获取购物车运输标签和成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆