WooCommerceでは、woocommerce_get_order_item_totals
フィルタークックを使用して、行の並べ替えなどの注文合計行をカスタマイズしていることをよく理解しています。
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のThankYouページで、合計よりも小計を再注文しようとしましたが、合計より下の支払い方法は成功しませんでした。私のPHPの知識は非常に限られており、助けていただければ幸いです。
注文テーブルから合計行をカスタマイズして、WooCommerceのありがとうページで並べ替える方法は?
以下は、Woocommerce thankyou (受注済み)ページでのみ、必要に応じてアイテムの合計を並べ替えます。
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;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加