Skip to content

Instantly share code, notes, and snippets.

@Tiex84
Created March 25, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Tiex84/68fd7452deafc9f553f5156dd696c383 to your computer and use it in GitHub Desktop.
Save Tiex84/68fd7452deafc9f553f5156dd696c383 to your computer and use it in GitHub Desktop.
<?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