Skip to content

Instantly share code, notes, and snippets.

@maagmirror
Created August 23, 2020 02:57
Show Gist options
  • Save maagmirror/f9b6720f37d933b8ec7945acdc89d893 to your computer and use it in GitHub Desktop.
Save maagmirror/f9b6720f37d933b8ec7945acdc89d893 to your computer and use it in GitHub Desktop.
<?php woocommerce_product_loop_start(); ?>
<?php foreach ( $related_products as $related_product ) : ?>
<?php
$post_object = get_post( $related_product->get_id() );
setup_postdata( $GLOBALS['post'] =& $post_object ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found
wc_get_template_part( 'content', 'product' );
?>
<!-- obtain id of the product -->
<p> <?php echo $related_product->get_id(); ?></p>
<?php endforeach; ?>
<?php woocommerce_product_loop_end(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment