Reputation: 743
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
I have this line in my functions.php
file. I got these hooks from the content-single-product.php
file. However, the related products on my single product page still exists.
I don't want to remove the functionality entirely, I duped their $args
to do my own query.
Updated
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);
I tried to write a function to achieve my goal, but the related products from the do_action
is still present. I can only think of CSS to do what I need, but I shouldn't have to rely on this.
Also, just for the sake of showing this, this is what's in the content-single.product.php
file:
<?php
/**
* woocommerce_after_single_product_summary hook.
*
* @hooked woocommerce_output_product_data_tabs - 10
* @hooked woocommerce_upsell_display - 15
* @hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
Upvotes: 3
Views: 3424
Reputation: 71
As LoicTheAztec correctly pointed out, your code is working fine. We tested it. The related products were removed but the upsell products were still there. We tested using storefront theme.
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 );
remove_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 15 );
}
add_action('init', 'remove_woo_relate_products', 10);
You can see that storefront_upsell_display
is calling the woocommerce_upsell_display
function storefront_upsell_display() {
woocommerce_upsell_display( -1, 3 );
}
So in this code, we have removed the theme's action for upsell. In the same logic, there is a possibility that related products function may be called in your theme. If this is the case you can remove the corresponding action for that.
Note: Make sure the code is in your current theme's functions.php
Upvotes: 4