douyujun0152 2014-08-24 14:16
浏览 26

WooCommerce产品直到价格

I want to create a page in WooCommerce that shows only product untilspecific price. For example I want to show all products that whose prices not big than 50$.

How i can do this? Thanks :)

  • 写回答

1条回答 默认 最新

  • duanmei1694 2014-08-25 13:52
    关注

    This can be achieved using the following code, by writing custom query:

    $paged = (get_query_var('paged'))? get_query_var('paged') : 1;  
    $price_limit = 50;  
    $args = array('paged' => $paged, 
                  'post_type' => array('product','product_variation') 
                  'post-status' =>'publish', 
                  'meta_key' => '_price', 
                  'meta_query' => array( 
                      array( 
                          'key' => '_price', 
                          'value' => $price_limit
                          'compare' => '<=', 
                           ) 
                  ) 
    );
    $wp_query = new WP_Query( $args );
    
    <?php if ( have_posts() ) : ?> 
        <?php while ( have_posts() ) : the_post(); ?>    
            <?php //code to represent product list ?>
        <?php endwhile; ?>
        <?php wp_reset_postdata(); ?> 
    <?php else : ?>
        <?php echo "Data not found"; ?> 
    <?php endif; ?>
    

    Here, change $price_limit value to as per the requirement.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作