Remove action fails to remove default WooCommerce hooked function

I am trying to move the product tabs from woocommerce_after_single_product_summary to woocommerce_before_single_product_summary. Essentially, I want to replace the image of the product on the single product with a tab that has the image gallery, but all the other tabs show up in that same container. I have issues trying to get the container around the tabs to act like the container around the image, but what's got me stumped is how to remove the tabs from the woocommerce_after_single_product_summary section. I can remove "related products" no problem, from the same section, but nothing I've done has budged the tabs.

This works fine to remove the image:

remove_action ('woocommerce_before_single_product_summary', 

This works fine to add the tabs in its place (Other than the container issue):

add_action( 'woocommerce_before_single_product_summary', 
'woocommerce_output_product_data_tabs', 20 );

But this never seems to get rid of the tabs:

remove_action( 'woocommerce_after_single_product_summary', 
'woocommerce_output_product_data_tabs', 10 );

I've checked that 10 is the correct number (which I found does make a difference) but it IS correct. I traced the add_action to woocommerce/includes/wc-template-hooks.php:

 * After Single Products Summary Div.
 * @see woocommerce_output_product_data_tabs()
 * @see woocommerce_upsell_display()
 * @see woocommerce_output_related_products()
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 );

I can remove related products with: remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

I've tried the suggestion (in another topic) that the hook might need a "template redirect" but that didn't work either. What I tried was:

    // Trying template redirect
    function esb_product_category_filter_changes()
    'woocommerce_output_product_data_tabs', 10); 

Any ideas? I've searched all the possibly relevant plugins, turned a bunch off, and still the same behavior. I can put the tabs anywhere I want, but I can't get rid of them.

1 answer

  • answered 2018-01-11 20:54 LoicTheAztec

    I have tested on Storefront theme:

    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );

    And it works. So your issue can be due to your theme or some plugins that are making some customizations on this.

    How to check it:
    With the following hooked function you will get the raw data output for woocommerce_after_single_product_summary hook (all callbacks, with priorities and arguments). This way you will be able to see if woocommerce_output_related_products is hooked in it and what is the priority.

    This testing function will output the data for admins only in archives and product pages:

    add_action( 'woocommerce_before_main_content', function(){
        // Only for admin user role
        if( ! current_user_can('edit_products')) return;
        global $wp_filter;
        echo '<pre>';
        print_r( $wp_filter['woocommerce_after_single_product_summary'] );
        echo '</pre>';
    }, 50 );

    Code goes in function.php file of the active child theme (or active theme).

    Now you can get the correct priority to set in the remove_action() (and remove this testing code).

    You could also try the following code (without any guaranty):

    add_action( 'woocommerce_after_single_product_summary', 'removing_product_tabs', 2 );
    function removing_product_tabs(){
        remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );

    Code goes in function.php file of the active child theme (or active theme).