The use of WC here means I don’t have a lot of suggestions: I don’t really use WC unless I absolutely have to because it makes me grumpy.
In this case I probably would have used a partial that expects certain data instead of WC’s templating system, so i could so something like this:
// app/filters.php
add_filter('sage/template/front-page/data', function (array $data) {
$data['products'] = array_map( function ($product) {
$featured_image_id = get_post_thumbnail_id($product->ID);
return array(
'name' => $product->post_title,
'link' => get_permalink($product),
'image' => $featured_image_id ? wp_get_attachment_image_src($featured_image_id, 'large') : false,
);
}, get_posts(array(
'post_type' => 'product',
'posts_per_page' => 12,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
),
),
)));
return $data;
});
// resources/views/front-page.blade.php
<div class="featured-products row">
@foreach($products as $product)
@include('products.featured', $product)
@endforeach
</div>
// resources/views/products/featured.blade.php
<div class="featured-product">
<h3>{{ $product['name'] }}</h3>
<img src="{{ $product['image'][0] }}">
<a href="{{ $product['link'] }}"></a>
</div>