Skip to content

Instantly share code, notes, and snippets.

@wpbean
Created July 15, 2024 20:25
Show Gist options
  • Save wpbean/bf35e79fbef8f087134b24297887ea43 to your computer and use it in GitHub Desktop.
Save wpbean/bf35e79fbef8f087134b24297887ea43 to your computer and use it in GitHub Desktop.
Woodmart Theme product video showing in product tab.
<?php
// Add the folowing code in your theme or child theme functions.php
add_filter( 'woocommerce_product_tabs', 'wpb_wiz_add_woodmart_video_product_tab', 9999 );
function wpb_wiz_add_woodmart_video_product_tab( $tabs ) {
$tabs['docs'] = array(
'title' => 'Videos',
'priority' => 50,
'callback' => 'wpb_wiz_add_woodmart_video_product_tab_content',
);
return $tabs;
}
function wpb_wiz_add_woodmart_video_product_tab_content() {
global $product;
$attachment_ids = $product->get_gallery_image_ids();
if ( has_post_thumbnail() ) {
$attachment_ids = wpb_wiz_unshift( $attachment_ids, get_post_thumbnail_id() );
}
$woodmart_wc_video_gallery = (array) get_post_meta( $product->get_id(), 'woodmart_wc_video_gallery', true );
if( isset($attachment_ids) && !empty($attachment_ids) ){
foreach ( $attachment_ids as $attachment_id ) {
// For Woodmart Theme
if( isset($woodmart_wc_video_gallery) && isset($woodmart_wc_video_gallery[$attachment_id]) ) {
$settings = $woodmart_wc_video_gallery[$attachment_id];
$video_url = $video_type = '';
if( isset( $settings['video_type'] ) ){
$video_type = $settings['video_type'];
if( 'youtube' === $video_type && '' !== $settings['youtube_url'] ) {
$video_url = $settings['youtube_url'];
}
if( 'mp4' === $video_type && '' !== $settings['upload_video_id'] ) {
$video_url = wp_get_attachment_url($settings['upload_video_id']);
}
if( 'vimeo' === $video_type && '' !== $settings['vimeo_url'] ) {
$video_url = $settings['vimeo_url'];
}
}
if( $video_url ){
if( 'mp4' === $video_type ){
echo wp_video_shortcode( array( 'src' => $video_url ) );
}else{
echo wp_oembed_get($video_url);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment