Dean
asked 4 years ago

Hi There DW

DW trendy theme have related products at the bottom of page with single product. At the moment showing only 2 product each time. I would like to show at least 6 related products on each page. How can I change this?

Thank you.

1 Answers
DominicStaff
answered 4 years ago

Hi,
To show at least 6 related products on each page, you can open the \dw-trendy\woocommerce\single-product\related.php file. Find the line 10.
Replace the following code:
'posts_per_page' => $posts_per_page,

With new code:
'posts_per_page' => 6,
Hope this helps !

deanl
replied 4 years ago

Thanks Dominic, its working, but showing not more than 5 products (even if I put 9 in code). YARPP plugin is great for related products, works perfectly. Could I use YARPP plugin and CSS from Trendy to achieve the best results?

dominic Staff
replied 4 years ago

If you want to showing more than 5 products in the Related section, you can open the related.php file
Replace all the codes line in the file with the following code:

<?php
/**
 * Related Products
 */

 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

 global $product, $woocommerce_loop;

 $related = $product->get_related( 10 );

 if ( sizeof( $related ) == 0 ) return;

 $args = apply_filters( 'woocommerce_related_products_args', array(
    'post_type'            => 'product',
    'ignore_sticky_posts'  => 1,
    'no_found_rows'        => 1,
    'posts_per_page'       => 10,
    'orderby'              => $orderby,
    'post__in'             => $related,
    'post__not_in'         => array( $product->id )
 ) );

 $products = new WP_Query( $args );

 $woocommerce_loop['columns'] = 4;

 if ( $products->have_posts() ) : ?>

    <div class="related products">

        <h2><?php _e( 'Related Products', 'woocommerce' ); ?></h2>

        <?php woocommerce_product_loop_start(); ?>

            <?php while ( $products->have_posts() ) : $products->the_post(); ?>

                <?php wc_get_template_part( 'content', 'product' ); ?>

            <?php endwhile; // end of the loop. ?>

        <?php woocommerce_product_loop_end(); ?>

    </div>

      <?php endif;

 wp_reset_postdata();

Then add the following code to the style.css file:

.related ul.products li:nth-child(5) {
    clear: left;
}
.related ul.products li:nth-child(9) {
    clear: left;
}

Hope this helps !

sudhabnrj
replied 2 years ago

Thanks @dominic

Dominic Staff
replied 2 years ago

You’re welcome. If you have any issue or question, you can let me know. We will check and help you resolve it.

Bulkly Info
replied 11 months ago

i am trying to show latest product on single page can suggest me how to show latest related product in single product page

thank you in advance

Dominic Staff
replied 10 months ago

Which theme are you using?

Powered by DW Question & Answer Pro