1 回答

TA貢獻1804條經驗 獲得超8個贊
以下內容將僅在 Woocommerce 謝謝(已收到訂單)頁面上根據需要重新排序商品總數:
add_filter( 'woocommerce_get_order_item_totals', 'reordering_order_item_totals', 10, 3 );
function reordering_order_item_totals( $total_rows, $order, $tax_display = '' ){
// Only on "order received" thankyou page
if ( ! is_wc_endpoint_url('order-received') )
return $total_rows;
$sorted_items_end = array('cart_subtotal', 'order_total', 'payment_method');
$sorted_total_rows = array(); // Initializing
// Loop through sorted totals item keys
foreach( $sorted_items_end as $item_key ) {
if( isset($total_rows[$item_key]) ) {
$sorted_total_rows[$item_key] = $total_rows[$item_key]; // Save sorted data in a new array
unset($total_rows[$item_key]); // Remove sorted data from default array
}
}
return array_merge( $total_rows, $sorted_total_rows); // merge arrays
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。經過測試并有效。
要使該功能在任何地方都適用于客戶訂單和電子郵件通知,只需刪除:
// Only on "order received" thankyou page
if ( ! is_wc_endpoint_url('order-received') )
return $total_rows;
- 1 回答
- 0 關注
- 94 瀏覽
添加回答
舉報