Skip to main content
Post Closed as "Not suitable for this site" by Pieter Goosen, Mark Kaplun, cybmeta, birgire, gmazzap
Tweeted twitter.com/#!/StackWordPress/status/404097364706992128
edited tags
Link
kaiser
  • 50.8k
  • 27
  • 150
  • 244

WooCommerce tags and hooks How to customize woocommerce related products?

added 4 characters in body
Source Link
user1752759
  • 667
  • 3
  • 10
  • 18

I have the following lines of code in my website that will display the related products at the bottom of my single product page in WooCommerce...

functions.php:

// display upsells and related products within dedicated div with different column and number of products
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(4,4); 
    $content = ob_get_clean();
    if($content) { $output .= $content; }

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

As it displays 4 products that have been categorized under the same name, how would I modify the above, to display the related tags instead?

For example, I have a product category called 'Automotive' and within this category, are a few tags - 'Holden', 'Ford', 'Toyota', 'Nissan' etc.

I would like it to display 4 products at the bottom, related to the tag of the product the user is currently viewing.

I have the following lines of code in my website that will display the related products at the bottom of my single product page in WooCommerce...

functions.php:

// display upsells and related products within dedicated div with different column and number of products
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(4,4); 
    $content = ob_get_clean();
    if($content) { $output .= $content; }

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

As it displays 4 products that have been categorized under the same name, how would I modify the above, to display the related tags instead?

For example, I have a product category called 'Automotive' and within this category, are a few tags - 'Holden', 'Ford', 'Toyota', 'Nissan' etc.

I would like it to display 4 products at the bottom, related to the tag of product the user is currently viewing.

I have the following lines of code in my website that will display the related products at the bottom of my single product page in WooCommerce...

functions.php:

// display upsells and related products within dedicated div with different column and number of products
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(4,4); 
    $content = ob_get_clean();
    if($content) { $output .= $content; }

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

As it displays 4 products that have been categorized under the same name, how would I modify the above, to display the related tags instead?

For example, I have a product category called 'Automotive' and within this category, are a few tags - 'Holden', 'Ford', 'Toyota', 'Nissan' etc.

I would like it to display 4 products at the bottom, related to the tag of the product the user is currently viewing.

added 266 characters in body
Source Link
user1752759
  • 667
  • 3
  • 10
  • 18
Loading
Source Link
user1752759
  • 667
  • 3
  • 10
  • 18
Loading