NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Hard

---- Last modified : Sep 11 2022

Estimated reading time : 1 minute, 40 seconds - 115 words

Removed related products for WordPress is quite simple to do. First thing we need to do is a remove_action inside the single Product.

// Remove related products from after single product hook
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
// Remove up sells from after single product hook
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );

To remplate the linked products, you need to use a hook filter to add an Up-Sell WooCommerce function and specify a different one for each single product. If there are no up-sell related products, we will display all other related products by default.

function via_upsell_related_cross() {
  if ( is_cart() ) {
    woocommerce_cross_sell_display();
  } elseif ( ! ( is_checkout() || is_front_page() || is_shop() || is_product_category() || is_product_tag() ) ) {
    global $product;
    $upsells = $product->get_upsells();
      if ( count( $upsells) > 0 ) {
        woocommerce_upsell_display( 4,4 );
      } else {
        woocommerce_output_related_products();
      }
  }
}
add_action( 'woocommerce_after_single_product_summary', 'via_upsell_related_cross',  20 );

Now login your Admin WordPress acount, select a WooComerce product and under the product’s data, click on Related Products and add your products.

up-sell-WooCommerce-300x95

When you look at the product, you’ll see similar products as up-sell. It’s a great way to increase sales and connect similar products.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>