Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable an action from template hooks in Wordpress' Woocommerce?

Here's a part of codes in wc-template-hooks.php:

add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

Here's the code from content-single-product.php

do_action( 'woocommerce_after_single_product_summary' );

What code should I put in content-single-product.php to remove woocommerce_output_related_products without editing the wc-template-hooks.php.

Sorry, I'm new in PHP. Thanks in advance.

like image 346
user1441816 Avatar asked Feb 11 '23 23:02

user1441816


2 Answers

You dont have to put it in content-single-product.php, try adding it to functions.php and if you just need to remove it on a single products page use woocommerce conditional functions to allow it only on the pages you want. for instance.

<?php if(is_product()){ 
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); }?>
like image 114
Omer Farooq Avatar answered Feb 13 '23 11:02

Omer Farooq


I have tried all above solutions but not working. Woo-commerce Version 3.4.1

Working Code, Added in child theme in functions.php

add_filter('woocommerce_product_related_posts_query', '__return_empty_array', 20);
like image 30
Nadeem0035 Avatar answered Feb 13 '23 11:02

Nadeem0035