Add custom product tabs to WooCommerce with PHP

Add, remove and rename WooCommerce product tabs

The single product page shows Description, Additional information and Reviews in tabs. Shops often need something else: a “Shipping and returns” tab with the same text for every product, a “Size guide” for clothes, a tab with a product-specific field, and no Reviews tab when the shop does not use reviews. All of it goes through one filter, woocommerce_product_tabs.

Problem: The product page should rename “Description”, hide the reviews tab, add a “Shipping and returns” tab with a global text, and show a “Size guide” tab only for products that have one.

Solution: Change the tabs array in the woocommerce_product_tabs filter: unset tabs to remove them, change title and priority, and add new entries with a callback that prints the content. Add tabs conditionally inside the filter, where the current product is available.

The filter

<?php
add_filter( 'woocommerce_product_tabs', function ( $tabs ) {
    global $product;

    // Rename
    if ( isset( $tabs['description'] ) ) {
        $tabs['description']['title'] = __( 'Details', 'textdomain' );
    }

    // Remove
    unset( $tabs['reviews'] );

    // A tab with the same text for every product
    $tabs['ha_shipping'] = array(
        'title'    => __( 'Shipping and returns', 'textdomain' ),
        'priority' => 30,
        'callback' => 'ha_shipping_tab',
    );

    // Only for products that have a size guide
    if ( $product && $product->get_meta( 'ha_size_guide' ) ) {
        $tabs['ha_size_guide'] = array(
            'title'    => __( 'Size guide', 'textdomain' ),
            'priority' => 25,
            'callback' => 'ha_size_guide_tab',
        );
    }

    return $tabs;
}, 98 );

function ha_shipping_tab() {
    echo '<h2>' . esc_html__( 'Shipping and returns', 'textdomain' ) . '</h2>';
    echo wp_kses_post( wpautop( get_option( 'ha_shipping_text', '' ) ) );
}

function ha_size_guide_tab() {
    global $product;
    echo wp_kses_post( wpautop( $product->get_meta( 'ha_size_guide' ) ) );
}

The default priorities are 10 (Description), 20 (Additional information) and 30 (Reviews); tabs are sorted by priority. Priority 98 on the filter runs it after other plugins that add tabs, so they can be renamed or removed too.

Keep the text of the shipping tab in one option (or a reusable block) instead of in every product, so a change of the return policy is one edit.

Tabs that disappear by themselves

WooCommerce removes the Description tab when the product has no description, and Additional information when it has no attributes, weight or dimensions. If you rename them, the rename also disappears in these cases, which is usually what you want.

Reviews can also be switched off for the whole shop in WooCommerce → Settings → Products → Enable product reviews, which removes the tab and the review data from the product schema. Unsetting the tab only hides it.

Without tabs

Some designs show the sections one below the other instead of in tabs. The tabs template is a WooCommerce template part; the simplest way is to keep the filter above for the content and change the layout with CSS, or replace single-product/tabs/tabs.php in the theme when the markup itself must change.

NOTE: Content inside tabs is in the HTML and can be indexed by search engines, but text hidden in an inactive tab is not visible on load. Put information that matters for the buying decision (price conditions, delivery time) where it is visible without a click, and use tabs for details.