Use default Woocommerce query in shortcode/template?

I am trying to build a custom shop page. For this page I am building a custom shortcode and I am trying to use the default (if that exists) Woocommerce query for showing products. I guess I need this because I would like woocommerce filter widgets, such as filter by price and filter by attribute, to work.

I tried creating my own query like

$args = array(
‘post_type’ => ‘product’);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( ‘content’, ‘product’ );
endwhile;
} else {
echo __( ‘No products found’ );
}
wp_reset_postdata();

But filtering products, through the WC filter widgets, has no effect on a query like this.
I also tried using a shortcode to retrieve the products like

[products]

This allowed me to filter by price, but not by attribute.

I was wondering if there is any way to use the default WC loop (like in archive-product.php / shop page) in order to retrieve products on my custom shop page AND keep the filter widgets active.

Any help is greatly appreciated!

Read more here:: Use default Woocommerce query in shortcode/template?

Leave a Reply

Your email address will not be published. Required fields are marked *