# Product Video Tab

> Adds a "Video" field to products and shows the video (YouTube, Vimeo or an uploaded MP4) in its own product tab.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, product-tabs, video, media
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-product-video-tab/

## Code

```php
add_action( 'woocommerce_product_options_general_product_data', function () {
    global $product_object;

    woocommerce_wp_text_input( array(
        'id'          => '_wpide_video_url',
        'label'       => 'Video URL',
        'type'        => 'url',
        'placeholder' => 'https://www.youtube.com/watch?v=...',
        'value'       => $product_object instanceof WC_Product ? $product_object->get_meta( '_wpide_video_url' ) : '',
    ) );
} );

add_action( 'woocommerce_admin_process_product_object', function ( $product ) {
    // phpcs:ignore WordPress.Security.NonceVerification -- WooCommerce verifies the product save nonce.
    if ( isset( $_POST['_wpide_video_url'] ) ) {
        $product->update_meta_data( '_wpide_video_url', esc_url_raw( wp_unslash( $_POST['_wpide_video_url'] ) ) );
    }
} );

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

    $url = $product instanceof WC_Product ? $product->get_meta( '_wpide_video_url' ) : '';

    if ( $url ) {
        $tabs['wpide_video'] = array(
            'title'    => 'Video',
            'priority' => 15,
            'callback' => function () use ( $url ) {
                if ( preg_match( '/\.(mp4|webm|ogv)(\?.*)?$/i', $url ) ) {
                    echo wp_video_shortcode( array( 'src' => esc_url( $url ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput
                    return;
                }

                $embed = $GLOBALS['wp_embed']->shortcode( array(), esc_url( $url ) );
                echo '<div class="wpide-video-tab">' . $embed . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput -- oEmbed output.
            },
        );
    }

    return $tabs;
} );
```

## Notes

Paste a YouTube or Vimeo link or a media library MP4 URL; WordPress caches the embed after the first view.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Product Video Tab" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
