2017-12-22 18 views
2

WooCommerce에서 주문 전자 메일 템플릿을 사용자 지정하고 "total"바로 위의 주문 세부 정보에서 "Shipping"을 두 번째로 지정해야합니다.WooCommerce 전자 메일 알림에서 주문 세부 사항 합계를 다시 정렬하십시오.

enter image description here

나는 이것에 대한 루프가 woocommerce> 템플릿> 이메일에서 "이메일 주문 details.php"페이지에 라인 (52)에 알고, 그래서 내 아이의 테마를 설정하지만 난 거기서 어디로 가야할지 모르겠다. 여기에 내가 노력하고있어입니다 : 예상대로

if ($totals = $order->get_order_item_totals()) { 
       $i = 0; 
       foreach ($totals as $total) { 
        $i++; 
        if($total['label'] === "Shipping"){ 
         //make second-last above total somehow 
        } 
        else{ 
         ?><tr> 
         <th class="td" scope="row" colspan="3" style="text-align:<?php echo $text_align; ?>; <?php echo (1 === $i) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th> 
         <td class="td" style="text-align:left; <?php echo (1 === $i) ? 'border-top-width: 4px;' : ''; ?>" colspan="1"><?php echo $total['value']; ?></td> 
         </tr><?php 
        } 
       } 
      } 

답변

1

woocommerce_get_order_item_totals 필터 후크에 꺾어 사용자 정의 기능을 사용하여 항목의 합계를 다시 정렬 할 수 있습니다 :

add_filter('woocommerce_get_order_item_totals', 'reordering_order_item_totals', 10, 3); 
function reordering_order_item_totals($total_rows, $order, $tax_display){ 
    // 1. saving the values of items totals to be reordered 
    $shipping = $total_rows['shipping']; 
    $order_total = $total_rows['order_total']; 

    // 2. remove items totals to be reordered 
    unset($total_rows['shipping']); 
    unset($total_rows['order_total']); 

    // 3 Reinsert removed items totals in the right order 
    $total_rows['shipping'] = $shipping; 
    $total_rows['order_total'] = $order_total; 

    return $total_rows; 
} 

코드의 function.php 파일에 간다 활성 어린이 테마 (또는 테마) 또는 모든 플러그인 파일에서.

테스트를 거쳐 작동합니다.

enter image description here

+1

완벽한 감사합니다. –