WooCommerce:仅在列表中显示打折产品

WooCommerce: Display ONLY discounted product in list

来自这个问题 WooCommerce: Display ONLY on-sale products in Shop 我试着展示那些打折的产品。但是每次它显示所有产品时都是 on_sale 。 我还尝试了 _sale_price 元键。但不明白我该如何解决我的问题。 我的代码的项目输出

我的 $args 变量

$args = array(
'post_type'      => 'product',
'order'          => 'ASC',
'meta_query'     => array(
    array(
        'key'           => '_sale_price',
        'value'         => 0,
        'compare'       => '>',
        'type'          => 'numeric'
    )
)
);

我也试过下面的代码。但结果相同

$args = array(
'post_type'      => 'product',
'posts_per_page' => 8,
'meta_query'     => array(
    'relation' => 'OR',
    array( // Simple products type
        'key'           => '_sale_price',
        'value'         => 0,
        'compare'       => '>',
        'type'          => 'numeric'
    ),
    array( // Variable products type
        'key'           => '_min_variation_sale_price',
        'value'         => 0,
        'compare'       => '>',
        'type'          => 'numeric'
    )
)
);

我是如何解决我的问题的。当我从管理面板发布产品时,我错了。我的代码是正确的。当我发布产品时,我将价格设置为促销价而不是正常价格。现在我删除了那些没有打折的产品销售价格。并将该价格置于正常价格之上。现在我的问题解决了。这是我的输出。

我在管理面板中的工作