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

Further Resources for Web Design and Development Enthusiasts

Alright! We've embarked on quite an adventure exploring the realms of this topic. But why stop there? The world of web design and development is vast, and there's always more to learn and discover. Let's dive into some resources that'll keep your knowledge fresh, your skills sharp, and your passion ignited:

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!