久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Woocommerce Admin Orders 列表中添加可排序的自定義

Add a sortable custom column in Woocommerce Admin Orders list(在 Woocommerce Admin Orders 列表中添加可排序的自定義列)
本文介紹了在 Woocommerce Admin Orders 列表中添加可排序的自定義列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 WooCommerce 的訂單"部分添加了一個自定義列,用于運輸郵政編碼.列及其值正確顯示.

I've added a custom column to the "Orders" section of WooCommerce for the shipping zip code. The column and its values appear correctly.

我無法弄清楚如何使該字段的排序起作用(單擊列標題).我可以找到使用鉤子manage_edit-shop_order_sortable_columns"提到的其他代碼示例,但這似乎不適用于該領域.

What I cannot figure out is how to make the sorting of this field work (clicking on the column header). Other code examples I could find mention using the hook "manage_edit-shop_order_sortable_columns", but this doesn't seem to be working for this field.

注意:我已經看到了關于此的其他 StackOverflow 問題,但似乎沒有一個可以進行排序.

Note: I've seen the other StackOverflow issues about this, but none seem to have sorting working.

/**
 * ADD ZIP CODE TO WOOCOMMERCE ORDERS LIST
 */

// Add column (working)
add_filter( 'manage_edit-shop_order_columns', 'custom_woo_columns_function' );
function custom_woo_columns_function( $columns ) {
    $new_columns = ( is_array( $columns ) ) ? $columns : array();
    unset( $new_columns[ 'order_actions' ] );

    // all of your columns will be added before the actions column
    $new_columns['zipcode'] = 'Zip Code';

    //stop editing
    $new_columns[ 'order_actions' ] = $columns[ 'order_actions' ];
    return $new_columns;
}

// Change order of columns (working)
add_action( 'manage_shop_order_posts_custom_column', 'custom_woo_admin_value', 2 );
function custom_woo_admin_value( $column ) {
    global $post;
    $zip_value = get_post_meta($post->ID, '_shipping_postcode', true);
    if ( $column == 'zipcode' ) {
        echo ( isset( $zip_value ) ? $zip_value : '' );
    }
}

// Sort by custom column (NOT WORKING)
add_filter( "manage_edit-shop_order_sortable_columns", 'custom_woo_admin_sort' );
function custom_woo_admin_sort( $columns )
{
    $custom = array(
        'zipcode'    => '_shipping_postcode',
    );
    return wp_parse_args( $custom, $columns );
}

推薦答案

我想通了.將把它留在這里供其他任何嘗試添加排序郵政編碼列的人使用.只需添加此附加操作.

I figured it out. Will leave this up here for anyone else trying to add a sorted zip code column. Just add this additional action.


// Make sorting by custom column work properly
add_action('pre_get_posts', 'custom_zipcode_orderby');
function custom_zipcode_orderby($query)
{
    if (!is_admin()) return;
    
    $orderby = $query->get('orderby');
    if ('_shipping_postcode' == $orderby) {
        $query->set('meta_key', '_shipping_postcode');
        $query->set('orderby', 'meta_value_num');
    }
}

這篇關于在 Woocommerce Admin Orders 列表中添加可排序的自定義列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 美女在线观看国产 | 国产精品免费观看 | 在线观看h视频 | 一区二区三区四区国产 | 欧美日韩一本 | 欧美午夜一区 | 一区二区三区不卡视频 | 国产专区在线 | 一区在线观看 | 天堂一区在线 | 免费不卡av | 成人小视频在线观看 | 国产一区二区精品在线 | 少妇精品久久久久久久久久 | 亚洲视频一区在线观看 | a免费在线| 夜夜久久| 国产精品视频网 | 亚洲高清视频一区二区 | 日本一区二区影视 | 国产欧美一区二区三区在线看 | 99久久日韩精品免费热麻豆美女 | 国产精品久久久久久久一区二区 | 小草久久久久久久久爱六 | 久久综合九色综合欧美狠狠 | 国产一区二区在线视频 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 午夜影院普通用户体验区 | 亚洲欧美日韩高清 | 久久9热| 亚洲精品在线观看网站 | 日韩毛片播放 | 精品一区国产 | 国产剧情一区二区三区 | 欧美精品一区二区三区在线播放 | 亚洲综合视频 | 欧美精选一区二区 | 国产乱码精品一区二区三区五月婷 | 国产精品久久久久久久久久久新郎 | 国产精品美女久久久久久免费 | 97操操 |