A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Display a video instead of the single product image

If you prefer to use a video to show your product then it is possible to remove the static image and thumbnail and insert the embed code from a YouTube video. NB: This code only applies to one product as specified by product ID.

		/**
 * Display a video instead of the single product image
 */

// Removes the product image and thumbnails and adds an embed link to a YouTube video.
// Only applies to one product as specified by product ID.
// https://www.businessbloomer.com/woocommerce-show-video-instead-featured-image/

add_action( 'woocommerce_before_single_product', 'cc_show_video_not_image' );

function cc_show_video_not_image() {
  // Do this for product ID = 282 only
   if (is_single('282')) {
    remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20);
    remove_action('woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20);
    add_action('woocommerce_before_single_product_summary', 'cc_show_product_video', 20);
  }
}
  
function cc_show_product_video() {
  echo '<div class="woocommerce-product-gallery">';
  // get video embed HTML from YouTube 
  echo '<iframe width="560" height="315" src="https://www.youtube.com/embed/j88DOPsZYyo" frameborder="0" allowfullscreen></iframe>';
  echo '</div>';
}
	
View Raw Code ID: 91165