Opulence Add More Related Products

Hi again!

My friend Sven from Russia asked me about Opulence theme with WooCommerce plugin.

If you already use this theme and also using WooCommerce, you may find a related product at the end of your single product. By default the number of related products are 2.

What Sven asked is about how to change/configure how many related products should be displayed.

Untitled

If you are browsing into WooCommerce documentation, you may find this code:

function woo_related_products_limit() {
  global $product;
	
	$args['posts_per_page'] = 6;
	return $args;
}
add_filter( 'woocommerce_related_products_args', 'woo_related_products_limit' );

If you try that code by adding it into your theme functions.php, that code will not work with Opulence theme since Opulence have its own custom related products loop (check out a file named related.php).

And again, if you set the number manually (by adding showposts at the loop) it also not working. So, how to make it work?

To make it work, you can add this code to your theme functions.php at the very end of it:

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products',10);
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);

function woocommerce_output_related_products() {
    $output = null;

    ob_start();
    woocommerce_related_products(3,3); 
    $content = ob_get_clean();
    if($content) { $output .= $content; }

    echo '<div class="clear"></div>' . $output;
}

At that code if you take a look at it, i’m setting 3 related products to be displayed. And that is how to make it.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s