Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaPansuriya/1f57c0e0d9d932c6bb7f7e61bf50b1c6 to your computer and use it in GitHub Desktop.
Save MinaPansuriya/1f57c0e0d9d932c6bb7f7e61bf50b1c6 to your computer and use it in GitHub Desktop.
/**
* @Title: WooCommerce - List All Products From a specific category
* @Author: Mina Pansuriya
* @Website: http://minapansuriya.com
* @Blog URL: http://minapansuriya.com/woocommerce-list-all-products-from-a-specific-category/
*/
<?php
$cat_name = 'Bags'; // Here replace Category name with yours
$product_cat = get_term_by( 'name', $cat_name, 'product_cat' );
$cat_slug = $product_cat->slug;
$args = array(
'product_cat' => $cat_slug,
'post_type' => 'product',
'orderby' => 'date',
'posts_per_page' => -1
);
$products_list = new WP_query($args);
if ($products_list->have_posts())
{
while ($products_list->have_posts()) : $products_list->the_post();
wc_get_template( 'single-product/title.php' );
endwhile;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment