Last active
July 25, 2020 09:21
-
-
Save jameshwartlopez/cf45e3106545445c537527d9b4a05502 to your computer and use it in GitHub Desktop.
Display featured products by category. See https://jameshwartlopez.com/plugin/get-featured-products-of-a-category/
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 featured products by category. on this case its "shirts" which is the slug of the category. | |
$query_args = array( | |
'featured' => true, | |
'category' => array( 'shirts' ), | |
); | |
$products = wc_get_products( $query_args ); | |
global $post; | |
$columns = wc_get_loop_prop( 'columns' ); | |
?> | |
<div class="woocommerce columns-<?php echo esc_attr( $columns ); ?>"> | |
<?php | |
woocommerce_product_loop_start(); | |
foreach ($products as $product) { | |
$post = get_post($product->get_id()); | |
setup_postdata($post); | |
wc_get_template_part('content', 'product'); | |
} | |
wp_reset_postdata(); | |
woocommerce_product_loop_end(); | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment