I have an array which has a couple of product SKU’s in it I want to dispay the products that are connected to the SKU’s.
I found the custom woocommerce product loop, but can’t find any documentation on how to extend this.
$skus = array(sku1, sku2, sku3);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
}
wp_reset_postdata();
2
Answers
You could try to do this
In a
WP_Query
, you will need to use a meta query to get products that are connected to an array of SKUs.The code:
Tested and works.
See
WP_Query
and custom field post meta parameters documentation