我有一个插件,该插件输出了我的订单的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()
获取并显示订单subtotal (但由于是格式的价格,我们需要清洁它):
// 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>
测试并起作用