Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently working on an e-commerce website and I met an problem. My client want a page e-boutique with all the product categories displayed, followed by 3 promoted products and a button "show all".

This "Show all" button is supposed to show all the product that the store contains with the default woocommerce sorting and paging.

First of all, I dunno I'm doing it the right way. What I have so far is the page showing the product categories and when on this page I click the "show all" button, I reload the page with a GET argument "/?all=1" and have the product displayed.

<a class="product-category-view-all" href="?all=1"><?php _e('View all'); ?></a>

(I copied the idea from this post Show all products on one page with WooCommerce)

And here is my code :

<div id="content" class="hfeed">
<h1><?php _e('The E-boutique'); ?></h1>

<?php
if (isset($_GET['all']))
{
    $args = array(
        'post_type' => 'product',
        'orderby' => $orderby,
    );
    $wp_query = new WP_Query($args);
    ?>

    <?php do_action('woocommerce_before_shop_loop'); // woocommerce sorting ?>

    <div class="clear"></div>
    <ul class="products-list">
        <?php woocommerce_product_subcategories(); ?>

        <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

            <?php woocommerce_get_template_part('content', 'product'); ?>

            <?php
        endwhile; // end of the loop. 
        wp_reset_query(); 
        ?>
    </ul>
    <div class="clear"></div>

    <?php do_action('woocommerce_after_shop_loop'); // woocommerce pagination   ?>

    <?php
}
else
{
    // Code to display the product categories with thumbnails.
}
?>

The products are well displayed and the select for the sorting is visible. When I want to change the sorting, the page is reloaded but the order isn't changed and the paging is set to 3 products per page but it is not respected. (the paging buttons aren't displayed).

I would like to add that it's my first website using wordpress and woocommerce.

Any help would be greatly appreciated. Thank you all !

share|improve this question
    
Hey, did you ever find an answer for this? If yes, please share. That will be highly appreciated. Thanks. –  Devner Jun 14 '13 at 15:50

1 Answer 1

up vote 3 down vote accepted

I didn't entirely resolved my problem. My client changed his mind and didn't want the sorting anymore.

But concerning the paging, I managed to have it working by adding a new arg in my query, here is the code that made it worked for me :

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(
        'post_type' => 'product',
        'paged' => $paged,
    );
    $wp_query = new WP_Query($args);

    if (isset($_GET['all']))
    {
        ?>

        <?php do_action('woocommerce_archive_description'); ?>

        <?php if (have_posts()) : ?>

            <?php
            // I don't want the sorting anymore
            //do_action('woocommerce_before_shop_loop');
            ?>

            <ul class = "products-list">
                <?php while (have_posts()) : the_post(); ?>

                    <?php woocommerce_get_template_part('content', 'product'); ?>

                <?php endwhile; // end of the loop.   ?>
            </ul>

            <?php
            /*  woocommerce pagination  */
            do_action('woocommerce_after_shop_loop');
            ?>

        <?php elseif (!woocommerce_product_subcategories(array('before' => woocommerce_product_loop_start(false), 'after' => woocommerce_product_loop_end(false)))) : ?>

            <?php woocommerce_get_template('loop/no-products-found.php'); ?>

        <?php endif; ?>
        <?php
    }
    else
    {
        // Code to display the product categories with thumbnails.
    }
?>

The $paged variable helps me to get the current page passed in the URL via GET.

Once again, I dunno if it is the best way to do it. But it did the job for me.

I hope it can help someone.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.