WordPress.org

Forums

WooCommerce - excelling eCommerce
[resolved] Remove "Related Products" from bottom of product pages (18 posts)

  1. lauracgeorge
    Member
    Posted 2 years ago #

    I've removed all the choices for "related products", upsells, and cross-sells in every product I have on my site (I don't like the way they format so gigantically, distracting the potential customer with shiny new things to look at, and distorting my pictures). Yet, two related products still show up at the bottom of each product page. Is there a line of code I could remove or something to get these to stop showing up?

    http://wordpress.org/extend/plugins/woocommerce/

  2. terrytsang
    Member
    Posted 2 years ago #

    Hi, you can try below code at your theme functions.php:

    /*
    * wc_remove_related_products
    *
    * Clear the query arguments for related products so none show.
    * Add this code to your theme functions.php file.
    */
    function wc_remove_related_products( $args ) {
      return array();
    }
    
    add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);
  3. jameskoster
    Member
    Plugin Author

    Posted 2 years ago #

    A slightly lighter solution (every byte counts!)

    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

  4. terrytsang
    Member
    Posted 2 years ago #

    thanks for the tips, james :)

  5. lauracgeorge
    Member
    Posted 2 years ago #

    Eep! I tried James' solution and totally screwed everything up!

    I can't get into my dashboard now. My site isn't working.
    I just popped the remove action code into the functions.php and holy crapola, batman!
    Is there something I can do in ftp to fix this ASAP and get myself back up and running tonight? Clearly I need to hire someone to fix this little bit of code for me.

  6. terrytsang
    Member
    Posted 2 years ago #

    Hi Laura, you can FTP and download your theme functions.php file, remove the newly added code, save and upload replace that.

    Hope it will get your site back.

  7. lauracgeorge
    Member
    Posted 2 years ago #

    Sweet! That was easy and I'm back in. Site functions. All is well. I'll hire a developer to handle this issue for me. Lesson learned! Thanks Terry for the quick response!!

  8. terrytsang
    Member
    Posted 2 years ago #

    You are welcome, Laura :)

    Have you tried below code (added to functions.php)?

    function wc_remove_related_products( $args ) {
      return array();
    }
    add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);
  9. lauracgeorge
    Member
    Posted 2 years ago #

    I'm much too scared to do it myself, but I'm saving these snippets of code to send to whoever I hire to handle it. Asking around for good pros right now. Thanks for another option! Hopefully one will work and things will look awesome.

  10. terrytsang
    Member
    Posted 2 years ago #

    Haha, ok. All the best, cheers!

  11. loosefast
    Member
    Posted 1 year ago #

    terrytsang
    thanks for the code!

  12. caseythehost
    Member
    Posted 1 year ago #

    terrytsang's code works great. Product Enquiry even works now for some reason.

  13. Doug
    Member
    Posted 1 year ago #

    Hi, Terry

    It is not working for me; can you look further and advise?

    http://usasharp.graphicsolutiongroup.com/product/knife-rack-plastic/

    Thank you,
    Doug

    P.S. Do you know why there is extra <div> appearing that adds 87px of space after the product image?

  14. LogoLogics
    Member
    Posted 1 year ago #

    This code from James works just fine for me:

    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

    Add it to your child themes functions.php

    Make sure you can acces your functions.php by ftp.
    In case after adding the code you can not acces your dashboard, go to functions.php by ftp and remove the code there.

    In my case non of that happened and worked like a charme!

    Annie

  15. lorenbm
    Member
    Posted 1 year ago #

    The code added worked for me!!

    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

    So thanks a lot for you ideas! :)

  16. OrgSpring
    Member
    Posted 1 year ago #

    James' initial code is fine.

    Woo uses an action hook in the content-single-product.php file, which you can find in this path:
    wp-content>>plugins>>woocommerce>>templates>>content-single-product.php.
    You'll notice around line 61 the section dealing with after single product summary, to which woocommerce_output_related_products is hooked.
    Removing that hook is the correct (and easy) way to get rid of those related products.

    Note:
    For those who had issues with the code. Dont edit that template file directly. the code below should go in your own functions.php file. Some times when you copy from the web and place into your code, depending on which editor you use, it can reformat quotes.
    make sure the code is exactly as it's shown here, and dont forget the trailing semi-colon.

    /* Disable Related products on single product pages */
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
  17. Praveen
    Member
    Posted 1 year ago #

    What does the 20 stand for in :

    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);

  18. John
    Member
    Posted 1 year ago #

    Hey, the 20 stands for the order in which the function is fired. Check this link <a href="http://www.kathyisawesome.com/412/thematic-hooks-and-functions/">php Basics</a> Kathy does a good job of explaining things.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic