1

我想用 FacetWP 排序方面替换 WooCommerce 排序。为此,我正在使用输出挂钩facetwp_sort_optionshttps ://facetwp.com/documentation/developers/output/facetwp_sort_options/

我已经替换了订单下拉菜单,但缺少 WooCommerce 订单选项。

现在我只设法按价格添加订单:

add_filter( 'facetwp_sort_options', function( $options, $params ) {

    $options['price_asc'] = array(
        'label' => 'Price: low to high',
        'query_args' => array(
            'meta_key' => '_price',
            'orderby' => 'meta_value_num',
            'order' => 'ASC'
         )
    );

    $options['price_desc'] = array(
        'label' => 'Price: high to low',
        'query_args' => array(
            'meta_key' => '_price',
            'orderby' => 'meta_value_num',
            'order' => 'DESC'
         )
    );
    return $options;

这个答案有帮助:https ://stackoverflow.com/a/46715264/1788961

但是我怎样才能添加其余的 WooCommerce 订单选项。有没有我可以使用的元字段列表?

我需要添加以下订单选项:

  • 默认顺序
  • 按人气排序
  • 按平均评分排序

编辑:删除了销售产品的选项(我自己想通了)

4

1 回答 1

1

从这个网站得到它

也许有帮助:

add_filter( 'facetwp_sort_options', function( $options, $params ) {
unset( $options['date_asc'] );
unset( $options['title_asc'] );
unset( $options['title_desc'] );
$options['default']['label'] = 'Standaard sortering';
$options['date_desc']['label'] = 'Sorteren op nieuwste';

$options['popularity_new'] = [
    'label' => 'Sorteer op populariteit',
    'query_args' => [
        'orderby' => 'post_views',
        'order' => 'DESC',
    ]
];
$options['price_asc'] = [
    'label' => 'Sorteer op prijs: laag naar hoog',
    'query_args' => [
        'orderby' => 'meta_value_num',
        'meta_key' => '_price',
        'order' => 'ASC',
    ]
];
$options['price_desc'] = [
    'label' => 'Sorteer op prijs: hoog naar laag',
    'query_args' => [
        'orderby' => 'meta_value_num',
        'meta_key' => '_price',
        'order' => 'DESC',
    ]
];

return $options;
}, 10, 2 );
于 2021-02-19T13:36:42.930 回答