Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何按$00产品的定价查询WooCommerce产品?_Jquery_Wordpress_Woocommerce_Wordpress Theming_Woocommerce Theming - Fatal编程技术网

Jquery 如何按$00产品的定价查询WooCommerce产品?

Jquery 如何按$00产品的定价查询WooCommerce产品?,jquery,wordpress,woocommerce,wordpress-theming,woocommerce-theming,Jquery,Wordpress,Woocommerce,Wordpress Theming,Woocommerce Theming,我的模板中有一个自定义查询,我想按价格显示产品,我想查询免费产品,并且只在我的主页上显示$0产品。将此添加到您的theme functions.php中,并让我知道它是否有效 add_action( 'woocommerce_product_query', 'zero_price_products' ); function zero_price_products( $q ){ $meta_query = $q->get( 'meta_query' ); $meta_

我的模板中有一个自定义查询,我想按价格显示产品,我想查询免费产品,并且只在我的主页上显示$0产品。

将此添加到您的theme functions.php中,并让我知道它是否有效

add_action( 'woocommerce_product_query', 'zero_price_products' );
function zero_price_products( $q ){
    $meta_query = $q->get( 'meta_query' );
        $meta_query[] = array(
        'key'       => '_price',
        'value'     => 0,
        'compare'   => '='
    );
    $q->set( 'meta_query', $meta_query );
}
如果要在主页上显示产品,请添加以下代码:

<?php
$args = array(
    'post_type' => 'product',
    'posts_per_page' => 8,
    'post_status' => 'publish',
    'orderby' => 'id',
    'order' => 'DESC',
    'meta_query' => array(
           array(
           'key'       => '_price',
           'compare'   => '=',
           'value'      => 0,
           )
        ),
);


$custom_posts = new WP_Query( $args );

if ($custom_posts->have_posts() ) : while ($custom_posts->have_posts() ) : $custom_posts->the_post(); ?>
    <?php
        wc_get_template_part( 'content', 'product' );
     ?>
<?php endwhile; endif; ?>

如何在主页上显示输出?这将改变所有存档页面的整个产品循环查询。这就是他所问的,我现在正在编写一个循环解决方案,而不改变所有产品。他只在主页上要求0.00美元的产品。我希望这对@MehediHasanMaruf有所帮助
$args = array(
            'post_type'      => 'product',
            'numberposts'      => -1,
            'meta_query'     => array(
                'relation' => 'OR',
                array(
                    'key'           => '_regular_price',
                    'compare' => 'NOT EXISTS'
                ),
                array( 
                    'key'           => '_price',
                    'compare' => 'NOT EXISTS'
                    
                ),
                array( 
                    'key'           => '_regular_price',
                    'compare' => '=',
                    'value' => 0,
                ),
                array( 
                    'key'           => '_price',
                    'compare' => '=',
                    'value' => 0,
                )
            )
        );
        
        $products =  get_posts( $args );