• Resolved bluedogranch

    (@bluedogranch)


    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 category product_cat.

    I’ve copied archive-product.php to the woocommerce folder in my child theme and renamed it custom-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.

    • This topic was modified 2 years, 11 months ago by bluedogranch.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @bluedogranch!

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Thread Starter bluedogranch

    (@bluedogranch)

    Thanks, but that’s surprising that it appears to be more complex to interact with woocommerce_product_loop_start rather than write a new WP_Query. I’d think there would be ways to hook into woocommerce_product_loop?

    Mirko P.

    (@rainfallnixfig)

    Hi @bluedogranch,

    This specific forum is more focused on the default WooCommerce core features. As already recommended, you might get more insights by posting your question on the above channels for developers.

    With regards to WooCommerce hooks, there is a dedicated section on our support documentation: https://woocommerce.com/document/introduction-to-hooks-actions-and-filters/.

    Cheers.

    Thread Starter bluedogranch

    (@bluedogranch)

    But you recommend using woocommerce_product_loop rather than WP_Query; “wc_get_products and WC_Product_Query provide a standard way of retrieving products that is safe to use and will not break due to database changes in future WooCommerce versions.” https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query

    Mirko P.

    (@rainfallnixfig)

    Hey @bluedogranch,

    Our support staff including myself are not developers that can give you recommendations on this. The channels mentioned above are the right ones to get in touch directly with expert developers that may assist you with your questions.

    For now, I’m going to leave this thread open a little longer in case a developer wants to step in to help you out.

    Thanks for your understanding.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution and the above resources for developers were helpful. If you have further questions, please feel free to open a new topic.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘woocommerce_product_loop_start to include categories’ is closed to new replies.