关于woocommerce订单的计算问题 - 详细信息总计

时间:2014-09-06 13:59:00

标签: php wordpress wordpress-plugin woocommerce

我正在为客户开发Wordpress + Woocommerce网站。他需要他的顾客提前支付30%的购物车,然后他们开始准备订单。

由于Woocommerce没有内置此预付款功能,我决定使用优惠券,自动申请订单总额的70%折扣(然后我将隐藏优惠券信息)。

对于1000欧元的购物车,客户会看到:Total = 300€
然后我添加一个“剩下付款”行,并在函数文件中显示结果进行简单计算:$woocommerce->cart->subtotal - $woocommerce->cart->cart_contents_total;
结果是折扣金额:在这种情况下为700欧元。

问题: 这在购物车和结帐页面上完美运行,但在订单详情页面上,“剩余付款”金额为0。

这是显示订单明细模板总计的代码(在woocommerce \ order中)。

<!-- show the totals on Order Details footer -->
    <?php
        if ( $totals = $order->get_order_item_totals() ) foreach ( $totals as $total ) :
            ?>
            <tr>
                <th scope="row"><?php echo $total['label']; ?></th>
                <td><?php echo $total['value']; ?></td>
            </tr>
            <?php
        endforeach;

    ?>

<!-- Trying to add the Left to pay line here -->
    <?php   if ( $totals = $order->get_order_item_totals() ) { ?>
        <tr class="order-total">
            <th>Left to pay</th>
            <td><?php echo number_format(custom_Total_Solde(),2,'.','')."€"; ?></td>
        </tr>

    <?php }; ?>

以下是我在函数上使用的代码来计算“剩下付款”的数量。

function custom_Total_Solde() {
    global $woocommerce;
    $solde = $woocommerce->cart->subtotal - $woocommerce->cart->cart_contents_total;
    return $solde;
}

任何人都知道如何计算订单详细信息的总数?它是否与购物车或结账时不同? 也许您知道订单详细信息总标签存储在哪个模板中?如果我能找到它,也许我可以理解为什么我的计算在这个特定的部分不起作用......

1 个答案:

答案 0 :(得分:1)

一旦您检查了购物车信息,我们就无法进行计算。

您需要查看WC_Order中的includes/class-wc-order.php课程。

$order->get_total()应该告诉您支付的总金额。因此,$order->get_total_discount()$order->get_cart_discount()可能会留下多少钱?

或者您可以使用以下钩子在结帐时创建订单时添加一些自定义元:

do_action( 'woocommerce_checkout_update_order_meta', $order_id, $this->posted );

我听说未来版本的WooCommerce将支持部分付款,但在此之前您还可以查看WooCommerce Deposit Plugin

PS- global $woocommerce已弃用,因此您应该习惯使用WC()