I want to display few related products in a grid on a single product page, code I am using
<?php
$product = new WC_Product(get_the_ID());
echo wc_price($product->get_price_including_tax(1,$product->get_price()));
?>
This shows the price of the main product on the website for each product on my list — the price of the product on which it is written, and not the price of each product on the grid.
Product price on single page is £9.00, every related product in products grid showing £9.00 instead of showing own price.
My complete code including ACF relation field:
<?php
$posts = get_field('related_set_1');
if( $posts ): ?>
<?php foreach( $posts as $p): ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>">
<?php
echo get_the_post_thumbnail( $p->ID, '175x100' )
?>
<div style="overflow:hidden">
<h4><?php echo $p->post_title; ?></h4>
<p class="price">
<?php
global $post;
$product = new WC_Product($post->ID);
echo wc_price($product->get_price_including_tax(1,$product->get_price()));
?>
</p>
<p class="link">View now</p>
</div>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
Using this in functions.php in filter function, If that does make a difference
add_filter( 'woocommerce_after_single_product_summary', 'custom_related_products' );
function custom_related_products() { ?>
.... (the code above here)
<php? }
I display it on another product tab, which I had to use
get_the_post_thumbnail( $p->ID, '175x100' )
despite
the_thumbnail
Is there a way to aim for a price, As otherwise I had the same problem and now everything works well, apart from the price.