Woocommerce插件需要按销售价格,价格订购

时间:2014-01-09 05:18:23

标签: wordpress wordpress-plugin woocommerce woothemes

我正在寻找具有多个订单的woocommrce排序,例如“orderby _sales_price,_price”。

get_catalog_ordering_args( $orderby = '', $order = '' ) {
switch ( $orderby ) {
        default :
             //Defult PATCH;
            //$args['orderby']  = 'menu_order title';
                            $args['orderby']  = 'meta_value_num';
            #$args['order']    = $order == 'DESC' ? 'DESC' : 'ASC';
                            $args['order']    = 'DESC';
            #$args['meta_key'] = '';
                            $args['meta_key'] = '_sale_price';
                            #echo "<pre>";print_r($ordering);exit;
        break;
    }

}

这里唯一重要的是我使用

在return参数中进行更改
$args['orderby']  = 'meta_value_num';
$args['order']    = 'DESC';
$args['meta_key'] = '_sale_price';

现在我的一级问题已修复,但我在这里通过多个字段的订单(如

)进行更多自定义
$args['orderby']  = 'meta_value_num';
$args['order']    = 'DESC';
$args['meta_key'] = '_sale_price, _price';

如果需要任何相关信息,请告诉我。

此致 Jigar

1 个答案:

答案 0 :(得分:0)

在这里我找到了答案。

if($q['post_type']=="product") {

    if($orderby ==="ORDER BY $wpdb->postmeta.meta_value+0 DESC") {
         $orderby_c = "ORDER BY pm1.meta_value+0 DESC,pm2.meta_value+0 DESC";
    } else if($orderby==="ORDER BY $wpdb->postmeta.meta_value+0 ASC") {
         $orderby_c = "ORDER BY pm1.meta_value+0 ASC,pm2.meta_value+0 ASC";
    } else {
         $orderby_c = "ORDER BY pm1.meta_value+0 DESC,pm2.meta_value+0 DESC";
    }

    $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts
                                          LEFT JOIN $wpdb->postmeta pm1 ON $wpdb->posts.ID = pm1.post_id
                                          LEFT JOIN $wpdb->postmeta pm2 ON $wpdb->posts.ID = pm2.post_id
                                          WHERE $wpdb->posts.post_type = 'product' AND $wpdb->posts.post_status = 'publish' 
                                          AND pm1.meta_key = '_sale_price' 
                                          AND pm2.meta_key = '_price' 
                                          $orderby_c $limits";

}