The solution with ACF relation field – post type ‘Products’ selected, and is set to ‘Post object’
<ul class=”slider sp-interested-too-carousel product-carousel-boxes”>
<?php
$theProducts = get_field(‘sp_interested_too_products_choosing’);
$theProductsIds = array();
foreach ($theProducts as $product) {
$theProductsIds[] = $product->ID;
}
$args = array(
‘post_type’ => ‘product’,
‘post__in’ => $theProductsIds,
‘posts_per_page’ => 10,
‘orderby’ => ‘rand’
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( ‘content’, ‘product’ );
endwhile;
} else {
echo __( ‘No products found’ );
}
wp_reset_postdata();
?>