All snippets

Add a custom WooCommerce product tab with PHP

Add a shared Care tab for physical products. The PHP example preserves existing tabs and explains template compatibility.

This snippet adds one shared Care tab. Use it for a brief general instruction applicable to physical products in your shop. Adapt the text to your catalogue before enabling it.

Installation and code

Add one language version to a PHP snippet set to run everywhere, or to your child theme’s functions.php. Test on a staging copy first. The example omits the opening PHP tag. Do not activate both language versions together.

add_filter( 'woocommerce_product_tabs', function ( $tabs ) {
    global $product;
    if ( ! $product instanceof WC_Product || $product->is_virtual() || $product->is_downloadable() ) { return $tabs; }
    if ( isset( $tabs['mmh_care_note'] ) ) { return $tabs; }
    $tabs['mmh_care_note'] = array(
        'title' => 'Care',
        'priority' => 35,
        'callback' => function () {
            echo '<p>' . esc_html( 'Follow the care instructions for your specific product. If you are unsure which method is suitable, contact us before using a cleaning product.' ) . '</p>';
        },
    );
    return $tabs;
}, 20 );

Usage and checks

Edit title for the label and the esc_html() string for the body. A lower priority normally places the tab earlier, subject to the theme. Test physical, virtual and downloadable items; the last two are excluded. An existing mmh_care_note tab is preserved.

Limitations and removal

The layout must execute woocommerce_product_tabs. Classic templates use it; current Product Details accordions can support custom tabs too. A page builder or replacement layout may bypass the filter. Variable products are checked at parent level, not for the selected variation. This example has no category rules or content editor.

Disable the snippet to remove its output. The examples use fixed language strings; connect them to your translation system for a multilingual store. PHP behaviour was checked on WordPress 7.1.5, WooCommerce 11.3.1 and PHP 8.4.23; verify appearance in your own theme or email template.

For several sections assigned by product or category, use Custom Product Tabs.

Technical reference