Created
November 24, 2023 06:36
-
-
Save manutheblacker/06b38849a8d9d1bb0fdf57dffe684bff to your computer and use it in GitHub Desktop.
Query Woo products from a specific category, in stock and display in a loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// display the title of the page related | |
add_filter('woocommerce_product_related_products_heading', '__return_false' ); | |
// WC query of products of a specific categories and in stock. | |
$wc_query = wc_get_products( array( | |
'post_type' => 'product', | |
'post_status'=>'public', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'ids', | |
'terms' => $product_categories, | |
'operator' => 'IN', | |
) | |
), | |
'stock_status' => 'instock' | |
) ); | |
// Display products from category by using Related products template file. | |
wc_get_template( | |
'single-product/related.php', | |
array( | |
'related_products' => $wc_query | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment