This project introduces a custom “Report” tab to WooCommerce product pages.
The tab appears only when:
- The product belongs to a specific category (default:
workshop) - The product has custom report content added from the admin meta box
This feature is ideal for displaying structured reports, summaries, workshop outcomes, course results, or any additional product-specific information.
- Adds a new WooCommerce product tab labeled “Report”
- Tab visibility depends on product category
- Includes a meta box with a full WordPress editor (
wp_editor) - Secure content storage using
wp_kses_post - Works with themes, child themes, or as part of a custom plugin
- Clean, minimal, and easy-to-maintain code
The functionality consists of:
- Filtering WooCommerce product tabs to register a custom tab
- Rendering tab content dynamically using post meta
- Creating a custom admin meta box for report content
- Saving report data on product update
You can use the code in two ways:
Paste the entire PHP code into your active theme or child theme’s functions.php.
Create a folder such as:
/woocommerce-report-tab/
report-tab.php- Copy the entire PHP code.
- Paste it into:
wp-content/themes/YOURTHEME/functions.php
- Create a folder inside:
wp-content/plugins/woocommerce-report-tab/ - Inside it, create a file:
report-tab.php - Paste the entire PHP code into it.
- Activate the plugin from WordPress Admin → Plugins.
The code checks if the product belongs to a specific category:
has_term( 'workshop', 'product_cat', $product->get_id() );If the product meets the conditions, a new tab titled report appears on the WooCommerce product page.
A meta box appears on the product edit pages in the WordPress admin.
This meta box allows entering report content using WordPress’s built-in rich text editor (wp_editor).
You can include text, images, or HTML content.
Any content entered in the meta box will appear inside the Report tab on the frontend product page.
The content is automatically sanitized using wp_kses_post() and wrapped in paragraphs with wpautop() for proper formatting.
Paste the following code into your plugin file or your theme’s functions.php:
// Add "Report" tab only for a specific product category
add_filter( 'woocommerce_product_tabs', 'add_report_tab_for_specific_category' );
function add_report_tab_for_specific_category( $tabs ) {
global $product;
$report_content = get_post_meta( $product->get_id(), '_report_content', true );
if ( has_term( 'workshop', 'product_cat', $product->get_id() ) && ! empty( $report_content ) ) {
$tabs['report_tab'] = array(
'title' => __( 'report', 'woocommerce' ),
'priority' => 15,
'callback' => 'report_tab_content'
);
}
return $tabs;
}
// Output the content of the "Report" tab
function report_tab_content() {
global $post;
$report_content = get_post_meta( $post->ID, '_report_content', true );
if ( ! empty( $report_content ) ) {
echo wpautop( wp_kses_post( $report_content ) );
}
}
// Add meta box for report content in admin
add_action( 'add_meta_boxes', 'add_report_content_metabox' );
function add_report_content_metabox() {
add_meta_box(
'report_content_box',
'Report Content (Product report)',
'report_content_metabox_html',
'product',
'normal',
'high'
);
}
// Meta box editor
function report_content_metabox_html( $post ) {
$value = get_post_meta( $post->ID, '_report_content', true );
wp_editor( $value, 'report_content_editor', array(
'textarea_name' => 'report_content',
'media_buttons' => true,
'textarea_rows' => 10,
'teeny' => false,
) );
}
// Save report content
add_action( 'save_post_product', 'save_report_content_meta' );
function save_report_content_meta( $post_id ) {
if ( isset( $_POST['report_content'] ) ) {
update_post_meta( $post_id, '_report_content', wp_kses_post( $_POST['report_content'] ) );
}
}To display the "Report" tab for a different product category, update the following line in the PHP code:
has_term( 'workshop', 'product_cat', $product->get_id() );Replace 'workshop' with the slug of your desired product category.
For example, to show the tab for products in the courses category:
has_term( 'courses', 'product_cat', $product->get_id() );- WordPress 6.x+
- WooCommerce 7.x / 8.x+
- PHP 7.4+ / PHP 8+
- Works with Classic Editor and Block Editor
MIT License — free to use, modify, and distribute.
Developed by Elaheh Akbarian
Contributions, forks, and suggestions are welcome.
This plugin/code snippet:
- Adds a conditional Report tab to WooCommerce products.
- Provides a rich-text meta box in the admin.
- Automatically displays sanitized content on the frontend.
- Fully compatible with WordPress and WooCommerce editors.