The title of the post actually says everything. I am trying to retrieve an ID from a WooCommerce product variation but it does not show anything.
I made a Custom Field - Post Object with:
Filter on post type: Product
Filter on Taxonmy: Product property
Working fine when selecting in a page but when I try to get the ID in template... Nothing.
Well not nothing because he is getting the ID of its parent. So the main product got ID 98, and two variations got 99 and 100. I need to get the ID of the variation because that is the field I selected.
How can I get the variation ID of the Post Object and not the ID of the main product?
I already searched in Google but no luck yet, also tried the documentation of Advanced Custom Fields but no luck either.
<?php
$post_object = get_field('post_object');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<span>Post Object Custom Field: <?php the_field('field_name'); ?></span>
</div>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>