[英]How to sort orders based on orders meta value in Woocommerce / Wordpress
我有一個Wordpress網站並安裝了Woocommerce,我在admin中顯示訂單以及一些我從訂購頁面收集並將它們存儲在與eoocommerce相關的其他表格中的額外值。
我們有基於WP post相關表中常見列的排序工具,但是我需要根據其他表中的字段對查詢進行排序。
如何實現呢? 任何幫助將不勝感激。
您需要做得更深入,並且您當然需要一些php知識來實現這一目標。 在一個項目中,我必須開發類似的東西,我共享代碼,但是您需要根據需要進行編輯。
// this action brings up a dropdown select box over the posts list in the dashboard
add_action('restrict_manage_posts','my_custom_restrict_manage_posts');
function my_custom_restrict_manage_posts() {
if( current_user_can('manage_options') ){
global $typenow;
global $wp_query;
global $woocommerce;
if ($typenow=='shop_order') {
// here you create your own selectbbox
// you can enqueue js using wc_enqueue_js()
}
}
}
function my_custom_orders_by_query( $vars ) {
global $typenow, $wp_query;
// check your filter that might come form the previous dropdown
if ( $typenow == 'shop_order' && isset( $_GET['select_box_name'] ) ) {
$meta_key = ''; // your meta key
$vars['meta_key'] = ''; // your meta value that came from the query string
// you might want this because that will show in the url of the page
$vars['meta_key'] = ''; // set meta key in the query var
$vars['meta_value'] = ''; // set meta value in the query var
}
return $vars;
}
add_filter( 'request', 'my_custom_orders_by_query' );
此代碼是最通用的代碼。 您需要自定義在標題中設置下拉框的方式以及鍵和值在request
過濾器中的反映方式。
如果您需要更多幫助,請隨時發表評論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.