Created
March 25, 2020 10:03
-
-
Save Tiex84/68fd7452deafc9f553f5156dd696c383 to your computer and use it in GitHub Desktop.
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 | |
$orderby = 'name'; | |
$order = 'asc'; | |
$hide_empty = true ; | |
$cat_args = array( | |
'orderby' => $orderby, | |
'order' => $order, | |
'hide_empty' => $hide_empty, | |
'exclude' => array(15 ), | |
); | |
$product_categories = get_terms( 'product_cat', $cat_args ); | |
if( !empty($product_categories) ){ | |
foreach ($product_categories as $key => $category) { | |
// echo $category->name; | |
echo | |
"<section id='featured' class='bg-primary py-5 mt-2'> | |
<div class='container'> | |
<ul class='row featured-products list-unstyled mb-0'>"; | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => 4, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => $category->slug | |
), | |
), | |
); | |
$loop = new WP_Query( $args ); | |
if ( $loop->have_posts() ) { | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
wc_get_template_part( 'content', 'featured' ); | |
endwhile; | |
} else { | |
echo __( 'No products found' ); | |
} | |
wp_reset_postdata(); | |
echo "</ul></div></section>"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment