
How to display related products in woocommerce single page with custom code
On Woo-Commerce product’s single page there needs to be display related products at bottom of the page. It’s a good thing to display the related products in the product details page so that customer can easily view the another products from the products details page. It’s a default features to display the related products on the products details page.
But when implement the product details page with custom, in that case we need to do with custom code. In this tutorial, we will show you how you can easily display the related products into the products details page on Woo-commerce. No need to use any WordPress plugin for showing the related products on the products details page.
Here is an example:
<?php $current_post_type = get_post_type('products'); $pro_args = array( 'posts_per_page' => 3, 'order' => 'DESC', 'orderby' => 'ID', 'post_type' => $current_post_type, 'post__not_in' => array( $post->ID ) ); // query for related products $rel_query = new WP_Query( $pro_args); // Check if there is any related posts if( $rel_query->have_posts() ) : ?> Related Products <?php // The Loop while ( $rel_query->have_posts() ) : $rel_query->the_post(); ?> <?php if(has_post_thumbnail()){ the_post_thumbnail(); } ?> <?php the_title() ?> <?php the_excerpt(); ?> <?php endwhile; ?> <?php endif; wp_reset_query(); ?>
Türkiye’nin en kaliteli porn videolarını sitemizden izleyebilirsiniz.