WordPress.org

Ready to get started?Download WordPress

Forums

Woocommerce - Paginated "On Sale" page (2 posts)

  1. tomiford
    Member
    Posted 11 months ago #

    Hi

    I need to create a paginated Product Archive page that lists all the woocommerce products that are "on sale" in a shop.

    I do not want to add a "Sale" category and manually assign products to that, it needs to get the products automatically.

    I found this post that almost answers my question but as I am new to wordpress I am not sure how I access the template "product-archive_sale.php" in a page template.

    Like the post in the above link I have copied woocommerce/product-archive.php to my theme and named it "woocommerce/product-archive_sale.php" and added the code below above 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 );

    This gets the sale products but now I don't know how to use it. I need to a URL like domain.com/sale/ that has the Woocommerce Sidebar on the page.

    Any advice is much appreciated.

  2. wlanni
    Member
    Posted 4 months ago #

    At the top of the product-archive_sale.php page, right after the opening <?php code, you need to add the template name stuff, e.g.:

    /**
    * Template Name: Sale Products
    * Description: The Template for displaying product archives, including the main shop page which is a post type archive.
    *

    http://codex.wordpress.org/Page_Templates#Custom_Page_Template

    Save and upload. The in your sale page, select the Sale Products template in the right column drop down for templates.

Reply

You must log in to post.

About this Topic