订单列表WooCommerce基于定制状态的元数据的订单

时间:2017-06-12 作者:Lipsum

我正在尝试创建名为“Priority Order”的自定义状态,当产品状态更改为“Priority Order”时,将自动添加post meta调用_priority_list 数字基于多少订单设置为优先级订单,我的问题是如何使用meta创建默认订单列表_priority_list? 这是我当前的代码:

function filter_priority_orders() {
    global $pagenow;
    $qv = &$query->query_vars;

    if ( $pagenow == \'edit.php\' && isset($qv[\'post_status\']) && $qv[\'post_status\'] == \'wc-priority-order\' ) {            
        $query->set(\'meta_key\', \'_priority_list\');
        $query->set(\'order_by\', \'_priority_list\');
    }

    return $query;
}
add_filter( \'pre_get_posts\', \'filter_priority_orders\' );
提前感谢!

1 个回复
最合适的回答,由SO网友:Lipsum 整理而成

我自己解决了我的问题,谢谢

function filter_priority_orders($query) {
    global $pagenow;
    $qv = $query->query_vars;

    if ( $pagenow == \'edit.php\' && 
        isset($qv[\'post_status\']) && $qv[\'post_status\'] == \'wc-priority-order\' && 
        isset($qv[\'post_type\']) && $qv[\'post_type\'] == \'shop_order\' ) 
        {            
        $query->set(\'meta_key\', \'_priority_list\');
        $query->set(\'orderby\', \'meta_value_num\');
        $query->set(\'order\', \'ASC\' );
    }

    return $query;
}

add_filter( \'pre_get_posts\', \'filter_priority_orders\' );

结束

相关推荐