亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自定義 WooCommerce 訂單表中的總行數

自定義 WooCommerce 訂單表中的總行數

PHP
慕斯709654 2023-09-22 14:48:14
在 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 感謝頁面上重新排序?
查看完整描述

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;


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 94 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號