【问题标题】:WooCommerce: Own sort/order dropdown (FacetWP)WooCommerce:自己的排序/订单下拉列表(FacetWP)
【发布时间】:2020-03-07 07:12:18
【问题描述】:

我想用 FacetWP 排序方面替换 WooCommerce 排序。 为此,我使用了输出钩子facetwp_sort_options:https://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 订单选项。 有没有我可以使用的元字段列表?

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

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

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

【问题讨论】:

  • _price_regular_price 是价格字段。 SELECT * FROM {yourprefix}_postmeta WHERE meta_key LIKE '%price%'
  • 嗨,我发现sale_price也是一个元字段。还是我错了?问题在于,过滤器按sale_price 排序(首先显示它们),但最后还会显示具有正常价格的产品。我只想展示促销产品。
  • 我不熟悉插件 facetWP,但您的 meta_query 看起来不像元查询。价格字段为_sale_price, _regular_price, _price
  • 价格字段的元查询(从高到低,反之亦然)效果很好。问题是我无法单独过滤_sale_price。它总是显示没有销售价格的产品。有什么选项可以在元查询中检查吗?
  • 我找到了销售价格检查的解决方案。必须添加以下代码:'value' => '', 'compare' => '!=' 到元查询 array

标签: wordpress woocommerce facetwp


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    相关资源
    最近更新 更多