25% off ProSNIPC25OFF

Add a Custom Product Information Tab

Appends an extra 'More Information' tab to the WooCommerce single-product tab row, populated from a custom product meta field.

PHPby SnipCraft
php
<?php
if ( ! class_exists( 'WooCommerce' ) ) {
    return;
}

/**
 * Populate the tab by setting the product meta _scseed_extra_tab_content.
 * The tab is hidden automatically when the meta is empty.
 */
add_filter( 'woocommerce_product_tabs', 'scseed_add_info_tab' );
function scseed_add_info_tab( $tabs ) {
    global $product;
    if ( ! $product ) {
        return $tabs;
    }
    $content = get_post_meta( $product->get_id(), '_scseed_extra_tab_content', true );
    if ( ! $content ) {
        return $tabs;
    }
    $tabs['scseed_info'] = array(
        'title'    => esc_html__( 'More Information', 'scseed' ),
        'priority' => 50,
        'callback' => 'scseed_info_tab_content',
    );
    return $tabs;
}

function scseed_info_tab_content() {
    global $product;
    if ( ! $product ) {
        return;
    }
    $content = get_post_meta( $product->get_id(), '_scseed_extra_tab_content', true );
    echo '<h2>' . esc_html__( 'More Information', 'scseed' ) . '</h2>';
    echo wp_kses_post( wpautop( $content ) );
}
#customization#display#products#tabs#woocommerce