woocommerce site related products display despite code to remove

I have a site using woocommerce. Both of these pieces of code from the woocommerce documentation should remove the display of related products on single product pages. I have used these before, they work. They do not work on this site http://testwpml.wpengine.com/shop/view-all-products/lil-clown-necklace/

The code is

function wc_remove_related_products( $args ) {
	return array();
}
add_filter('woocommerce_related_products_args','wc_remove_related_products', 30);
	}

and also tried this, in fact both at once even!

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

any ideas? It is a woo theme as well (myStile). I have a child theme and the code is in the functions.php

  • Patrick

    Hi there @mark_gason

    Welcome to WPMU DEV, glad to have you aboard!

    Three things come to mind:

    _ I'm astonished that there is no option in Woo to toggle that on/off.
    - Just to be clear; is the code in the child-theme functions.php or is it in the parent?
    - Are the other sites where the code does work also hosted at WP-Engine? Are they staging sites too, or are they live?

    Have you tried perhaps simply hiding that section on single products with a bit of CSS like so:
    .single-product .upsells {display:none;}

  • mark_gason

    thanks for the response.
    -woocommerce does not have a toggle. My woo theme does. It is set to not display.
    -functions.php is in my child theme.
    -Other sites where it works are not at WP Engine, but I don't think that is an issue.
    -The site I pointed you to is not what Wp Engine calls a 'staging' site. It is actually a full production environment duplicate. It was necessary for some other reasons related to multi-lingual testing .
    -On the live site right now I am hiding it with CSS. On the one you looked at which is for testing it is not done. I am hoping to do it with PHP as I would rather not have that query run unnecessarily. related products is a hefty query.

  • Sajid

    Hi @mark_gason

    Hope you are doing good today :slight_smile:

    I suggest you to call remove action on init or after theme setup.

    function remove_woo_relate_products(){
    	remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
    	remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
    }
    
    add_action('init', 'remove_woo_relate_products', 10);

    Let me know how it goes :slight_smile:

    Cheers, Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.