WooCommerce: Display ONLY on-sale products in Shop

前端 未结 5 1380
花落未央
花落未央 2020-12-08 11:57

I need to create a products archive page (usually the Shop page in WooCommerce) but displays ONLY the ON SALE<

5条回答
  •  悲哀的现实
    2020-12-08 12:35

    I managed to filter out the ON SALE products with the code below placed just above the if ( have_posts() ) : line...

    $args = array(
        'post_type'      => 'product',
        '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'
            )
        )
    );
    
    query_posts( $args );
    

    The code is placed in a copy of archive-product.php which I renamed archive-product_sale.php and made as a page template.

提交回复
热议问题