woocommerce_product_loop_start to include categories
-
I’m building a custom category archive template using
archive-product.php
as a base. What I need to do is show only products from some categories by using the ID of the product categoryproduct_cat
.I’ve copied
archive-product.php
to the woocommerce folder in my child theme and renamed itcustom-category-archive.php
, and it has a header of/*
Template Name: Custom Category Archive Template
*/so I can select it as a page template in the page editor.
This is the original Woocommerce product loop in the new template
custom-category-archive.php
:if ( woocommerce_product_loop() ) {
/**
* Hook: woocommerce_before_shop_loop.
*
* @hooked woocommerce_output_all_notices – 10
* @hooked woocommerce_result_count – 20
* @hooked woocommerce_catalog_ordering – 30
*/
do_action( ‘woocommerce_before_shop_loop’ );woocommerce_product_loop_start();
if ( wc_get_loop_prop( ‘total’ ) ) {
while ( have_posts() ) {
the_post();/**
* Hook: woocommerce_shop_loop.
*/
do_action( ‘woocommerce_shop_loop’ );wc_get_template_part( ‘content’, ‘product’ );
}
}woocommerce_product_loop_end();
How do I modify the woocommerce_product_loop_start loop to include only the products in the product category by using the category ID? I.e., only the products which are in the product categories as examples
12, 345, 7899
.I can include categories in a loop using a new WP_Query, but I want to see if it is possible to use woocommerce_product_loop_start.
- The topic ‘woocommerce_product_loop_start to include categories’ is closed to new replies.