在页面上显示 Woocommerce 中低于特定价格的所有产品 [英] Display on a page all products below a specific price in Woocommerce

查看:28
本文介绍了在页面上显示 Woocommerce 中低于特定价格的所有产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Woocommerce 商店,里面有 1000 多种产品.我希望所有价格低于 999 的产品都显示在单独的页面上,以便我可以在菜单中标记该页面.

有可能吗?

解决方案

更新: (将 'type' => 'DECIMAL', 添加到meta_query 数组)

这可以使用

您将获得:

2) 展示超过特定数量的产品

您将粘贴以下短代码示例,并带有 class 参数值 above-50 (对于价格高于 <代码>50):

[products limit="16";分页=真"列=4"班级=50 岁以上"]


可用的简码参数和设置:Woocommerce 简码文档

I have a Woocommerce store with more than 1000 products. I would like that all products which have a price below 999 should be shown on a separate page, so I can tag that Page in my menu.

Is it possible?

解决方案

Update: (added 'type' => 'DECIMAL', to the meta_query array)

This can be done using Woocommerce shortcode [products] to be used on a page, with the following additional code (that will add the possibility to define a price to be compared through an existing argument):

add_filter( 'woocommerce_shortcode_products_query', 'products_based_on_price', 10, 3 );
function products_based_on_price( $query_args, $atts, $loop_name ) {
    if( ! ( isset($atts['class']) && ! empty($atts['class']) ) )
        return $query_args;

    if (strpos($atts['class'], 'below-') !== false) {
        $compare   = '<';
        $slug    = 'below-';
    } elseif (strpos($atts['class'], 'above-') !== false) {
        $compare   = '<';
        $slug    = 'above-';
    }

    if( isset($compare) ) {
        $query_args['meta_query'][] = array(
            'key'     => '_price',
            'value'   => (float) str_replace($slug, '', $atts['class']),
            'type'    => 'DECIMAL',
            'compare' => $compare,
        );
    }
    return $query_args;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.


##USAGE:

Here we use the unused class argument to pass the price and the comparison operator.

1) DISPLAY PRODUCTS BELOW A SPECIFIC AMOUNT (YOUR CASE)

You will paste the following shortcode example with as class argument value below-999 (for products that have a price below 999):

[products limit="16" paginate="true" columns="4" class="below-999"]

The wordpress page text content editor:

You will get:

2) DISPLAY PRODUCTS ABOVE A SPECIFIC AMOUNT

You will paste the following shortcode example with as class argument value above-50 (for products that have a price above 50):

[products limit="16" paginate="true" columns="4" class="above-50"]


Available shortcode arguments and settings: Woocommerce shortcodes documentation

这篇关于在页面上显示 Woocommerce 中低于特定价格的所有产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆