Hi, i want to do the same thing, but inside my post.
to describe it more, here is what i have:
within my post i can already return the price of the product that are selected in the ACF relation field (product_id).
the code is:
<?php
$price = get_field('product_id');
if( $price ): ?>
<?php foreach( $price as $p): ?>
<?php global $post;
$product = new WC_Product($p->ID);
echo wc_price( $product->price );
?>
<?php endforeach; ?>
<?php endif;
?>
now i try the same thing, but i don’t want to output the price only, but the whole product instead.
I tried to replace the code with something like this:
<ul class="product">
<?php
$id = get_field('product_id');
$args = array(
'post_type' => 'product',
'post__in' => $id
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
echo '</div>';
endwhile;
}
wp_reset_postdata();
?>
</ul><!--/.product-->
but it ofc displays all products from the post type ‘product’.
how can i get the correct output, with the products that i’ve selected with the acf relationships field?