2017-12-12 11 views
1

私の注文のPDFを出力するプラグインがあります。セクションの1つに注文合計が表示されます。現在は合計が表示されていますが、小計(つまり、クーポンなどが適用される前の注文額)が表示されます。WooCommerceで注文小計を取得

誰でも手助けできますか?

これは、現在のコードです:

$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> 

答えて

1

更新日:

をご注文の小計を(取得し、表示する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> 

テストされ、動作します

+0

おかげで素晴らしい作品です。小売価格:100ポンドと割引価格: - 20ポンド。最後にTotal:£80 – Zed0121

+0

小計は、テストしたときに£0と表示され、6.40だったはずです。私はwoocommerce 3.2.4と最新のWordpressのバージョンを使用しています。 – Zed0121

+1

私はそれを以下に変更し、それは働いた! //注文小計を取得 $ order_subtotal = $ order-> get_subtotal(); 私の番号には最終的な0がありません。価格が£25.10の場合は£25.1と表示されます 価格が£33.33の場合、正しく表示されています。通貨が0で終わった場合にのみ、それは落ちる。 – Zed0121

関連する問題