I have a template file that is being called via wp_ajax that returns data from a specific WooCommerce product.

In the "tabs" section of the template file every tab is working fine:

  • Description - Good
  • Additional Information - Good
  • Custom Tab - Good

The only tab not rendering tab panel content is the reviews tab.

Interestingly the Tab Link (li) shows up with the correct tab count. However, when you click the link and the review panel is no longer display:none and set as active - no content is shown. (This has been verified in dev tools).

The code that is calling all of the individual tabs is:

<?php call_user_func( $tab['callback'], $key, $tab ) ?>

Where $tab is an array with:

  • title
  • priority
  • callback

The reviews tab calls the WooCommerce specified comments_template callback.

This is supposed to trigger the hook in class WC_Template_Loader:

add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) );

In testing I've var_dumped the WC_Template_Loader init function, and the init function, where the add_filters are located, is running.

However, when I var_dump a test string in the comments_template_loader() function, nothing is returned.

As an aside - all other WooCommerce generated content is rendered correctly (global $woocommerce, $post, $product are declared).

Why is this filter not running when seemingly all other default Wordpress tab filters are?

  • This is a woocommerce template file located within your theme? Possible the native tools are grabbing the wrong file? (hint) I'm hoping you aren't changing a single byte of code anywhere within the Plugin Woocommerce directory. (hint: I've been burnt before working on the wrong custom template.. now I always include <!-- custom_filename.php --> at the top of all customization's, then religiously ensure filenames are accurate.) – zipzit Jul 1 '15 at 17:23
  • @zipzit The changes in the WC code are strictly to see what is running. The problem seems to be that the file is never being grabbed. I.e. the comments_template_loader() never runs to process the file so the add_filter never is called. – W00tW00t111 Jul 1 '15 at 17:42

Alternatively, you could change the callback of the reviews tab to your own function which calls a custom template.


add_filter( 'woocommerce_product_tabs', 'fpusa_custom_review_tab', 98 );
function fpusa_custom_review_tab( $tabs ) {
    // change the callback for the reviews tab
    $tabs['reviews']['callback'] = 'fpusa_get_comments_template';
    return $tabs;

function fpusa_get_comments_template(){
    // looks for a file in /yourtheme/woocommerce/single-product/customer_reviews.php

Okay, for anyone looking to include the WooCommerce review tab not on an actual single-product page here's the secret sauce:

In your template file, you need:

global $withcomments;
$withcomments = true;

Then add a filter for the comments template:

//add filter to use our custom review template

* Hook function for using custom quickview review template
* @return [string] [file path to the template]
    $template = LCS_DIR . "../templates/tmpl-single-product-reviews.php";
    if ( file_exists( $template ) )
        return( $template );

$template is the full file path to the template file you want to use.

BadaBing and you're done!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.