[英]Customize total rows from WooCommerce order table
在 WooCommerce 中,我很了解woocommerce_get_order_item_totals
過濾器 kook 用於自定義訂單總行,例如重新排序。
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_of_from_order_table', 10, 2 );
function woocommerce_get_order_item_totals( $total_rows, $order ) {
// code here
return $total_rows;
}
我試圖在 WooCommerce 謝謝頁面上重新排序小計超過總和低於總的付款方式沒有成功。 我的 PHP 知識非常有限,感謝任何幫助。
如何自定義訂單表中的總行數,在 WooCommerce 感謝頁面上重新排序?
以下僅在 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 文件。 測試和工作。
為了讓客戶訂單和 email 通知無處不在,只需刪除:
// Only on "order received" thankyou page
if ( ! is_wc_endpoint_url('order-received') )
return $total_rows;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.