gpt4 book ai didi

php - 在 WooCommerce 中获取订单小计

转载 作者:行者123 更新时间:2023-12-04 03:02:41 25 4
gpt4 key购买 nike

我有一个插件可以输出我的订单的 PDF 文件。其中一个部分显示订单总数。目前这显示总计,但我希望它显示小计(即应用任何优惠券等之前的订单金额)。

有人能帮忙吗?

这是当前代码:

    $order_total = is_callable(array($order, 'get_total')) ? $order->get_total() : $order->order_total; ?>

<p id="order-total">
<b><?php _e('ORDER TOTAL:', 'woocommerce');?></b>
<span id="order-total-price">£<?php echo $order_total;?></span>

最佳答案

更新:

您可以使用 WC_Abstract_Order 方法 get_subtotal_to_display() 获取并显示订单小计 (但由于它是格式化价格,我们需要对其进行清理):

// Get the currency symbol
$currency_symbol = get_woocommerce_currency_symbol( get_woocommerce_currency() );

// Get order total
$order_total = is_callable(array($order, 'get_total')) ? $order->get_total() : $order->order_total;

// Get order subtotal
$order_subtotal = $order->get_subtotal();
// Get the correct number format (2 decimals)
$order_subtotal = number_format( $order_subtotal, 2 );

// Get order total discount
$order_discount_total = $order->get_discount_total();
// Get the correct number format (2 decimals)
$order_discount_total = number_format( $order_discount_total, 2 );

?>
<p id="order-subtotal">
<b><?php _e('ORDER SUBTOTAL:', 'woocommerce');?></b>
<span id="order-subtotal-price"><?php echo $currency_symbol . $order_subtotal;?></span>
</p>
<p id="order-total-discount">
<b><?php _e('ORDER DISCOUNT TOTAL:', 'woocommerce');?></b>
<span id="order-total-discount-price"><?php echo $currency_symbol . $order_discount_total;?></span>
</p>
<p id="order-total">
<b><?php _e('ORDER TOTAL:', 'woocommerce');?></b>
<span id="order-total-price"><?php echo $currency_symbol . $order_total;?></span>
</p>

已测试并有效

关于php - 在 WooCommerce 中获取订单小计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47777813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com