Auto-populate WooCommerce Category page with Essential Grid

The following code snippet can be used to auto-populate a grid for your WooCommerce product category pages.

The code below can be added to one of your WooCommerce page templates, such as “archive-product.php”.

<?php

    $ids = array();
    $cat = get_query_var('product_cat');
    $args = array( 'post_type' => 'product', 'product_cat' => $cat );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

        $ids[] = $loop->post->ID;

    endwhile;
    wp_reset_query();

    // replace "my-grid" with the alias name from one of your grids
    echo do_shortcode('[ess_grid alias="my-grid" posts="'.implode(',', $ids).'"]');

?>
Auto-populate WooCommerce Category page with Essential Grid

The Author

KC

Strength does not come from winning. Your struggles develop your strengths. When you go through hardships and decide not to surrender, that is strength.

Liked this Post?
Please Share it!

[tp_popular title="Popular Grids" regex="(grids|template_library)" count=3]

Newsletter

Join over 25.000 others on the Essential Grid and Slider Revolution email list to get access to the latest news and exclusive content.