Hide upsell in single product page

[ad_1]

Hi @panconpescao,

is there any code to hide the related products section when there is an upsell sectio in the single product page?

From what I understand, you’re looking for a way to hide the related products section on the single product page when an upsell section is present.

You can achieve this by using the following code snippet:

add_action( 'woocommerce_after_single_product_summary', 'remove_related_products', 1 );
function remove_related_products() {
global $product;

$upsells = $product->get_upsell_ids();

if ( count( $upsells ) > 0 ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
}
}

Here’s an image for your reference:

Image Link: https://s5.gifyu.com/images/SiSuA.gif

You should add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, like the Code Snippets plugin. Please note that it’s not advisable to add custom code directly to your parent theme’s functions.php file. Doing so could lead to the code being erased when the theme is updated.

📌 Just a quick reminder: Before you make any changes, we strongly recommend that you create a backup of your full site and database. This is a crucial step to ensure that in case anything goes wrong, you can easily restore your site to its previous, functioning state.

I hope this helps! If you have any other questions or run into any issues, please don’t hesitate to ask.

Yes that works perfectly, thank you!

Hi @panconpescao,

Yes that works perfectly, thank you!

I’m glad to hear that the solution worked perfectly for you! It’s always our goal to help resolve your inquiries as quickly and efficiently as possible.

I’ll go ahead and mark this thread as resolved. However, if you ever have more questions or issues in the future, don’t hesitate to kick off a new topic.

We’d be thrilled if you could spare a few minutes to leave us a review at 👉 https://projectdmc.org/support/plugin/woocommerce/reviews.

Cheers!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer