WooCommerce:拥有 sort/order 下拉菜单 (FacetWP)

WooCommerce: Own sort/order dropdown (FacetWP)

我想用 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;

这个回答有帮助:

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

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

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

Got it from this site

可能有帮助:

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 );