2017-12-12 1 views
1

주문한 PDF를 출력하는 플러그인이 있습니다. 섹션 중 하나에 주문 총계가 표시됩니다. 현재 총계가 표시되지만 소계 (쿠폰 등을 적용하기 전에 주문량)를 표시하고 싶습니다.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

부분합은 테스트했을 때 £ 6.40이었을 때 £ 0로 표시되었습니다. 나는 woocommerce 3.2.4 및 최신 Wordpress 버전을 사용하고 있습니다. – Zed0121

+1

다음과 같이 변경하여 효과가있었습니다! // 주문 부분 합계 $ order_subtotal = $ order-> get_subtotal(); 오직 내 번호에 마지막 0이 누락되었습니다. 예 : 가격이 £ 25.10 인 경우 £ 25.1로 표시됩니다. 가격이 £ 33.33 인 경우 올바르게 표시됩니다. 통화가 0으로 끝나는 경우에만 통화가 끊깁니다. – Zed0121

관련 문제