【问题标题】:Modify Woocommerce query to show only products with sale price修改 Woocommerce 查询以仅显示具有销售价格的产品
【发布时间】:2015-09-18 00:41:15
【问题描述】:

我一直在使用 wordpress 主题 Enfold,其中包含用于显示 Woocommerce 产品的产品滑块的简码。还包括用于编辑查询的过滤器:

$query = apply_filters('avia_product_slide_query', $query, $params);

默认查询变量如下所示:

Array(
[post_type] => product
[post_status] => publish
[ignore_sticky_posts] => 1
[paged] => 1
[offset] => 0
[post__not_in] => Array ( )
[posts_per_page] => 9
[orderby] => menu_order title
[order] => ASC
[meta_query] => Array (
    [0] => Array (
        [key] => _visibility
        [value] => Array (
            [0] => visible
            [1] => catalog
            )
        [compare] => IN
        )
    )
[tax_query] => Array (
    [0] => Array (
        [taxonomy] => product_cat
        [field] => id
        [terms] => Array (
            [0] => 13
            [1] => 64
            [2] => 65
            [3] => 15
            [4] => 67
            [5] => 66
            [6] => 23
            [7] => 73
            [8] => 75
            [9] => 10
            [10] => 52
            [11] => 53
            [12] => 50
            [13] => 51
            [14] => 12
            [15] => 48
            [16] => 11
            [17] => 44
            [18] => 14
            [19] => 55
            )
        [operator] => IN
        )
    )
)

有人知道如何在此查询中添加一些过滤器以仅显示已定义销售价格的产品吗?

【问题讨论】:

  • 您有 woocommerce 默认短代码 [sale_products per_page="12"],或者您可以深入了解 woocommerce 文件,看看他们是如何查询的。或者,在 Enfold 支持论坛上提问 ;)
  • Sale_products 短代码在这种情况下对我不利,因为我需要将产品显示为滑块。但多亏了这一点,我在文件 class-wc-shortcodes.php 中找到了我需要的这个简码的函数。感谢您的帮助。
  • 没问题,乐于助人:)

标签: wordpress woocommerce


【解决方案1】:

最后我是这样解决的:

$query['post__in'] = array_merge( array( 0 ), wc_get_product_ids_on_sale() ); 

【讨论】:

    猜你喜欢
    • 2020-08-21
    • 2019-09-16
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多