Home » WooCommerce: Show Video Instead of Product Images

WooCommerce: Show Video Instead of Product Images

by Tutor Aspire

This week’s snippet is a very easy – yet helpful – one. Many ecommerce entrepreneurs prefer to display a YouTube video instead of a static, boring, featured image and product gallery.

Of course, not all products are created equal. So, let’s see how to make this work for a specific product ID only. Enjoy!

Show video instead of featured image and product gallery on the WooCommerce Single Product page

PHP Snippet: Display Video instead of Product Images – WooCommerce Single Product Page

/**
 * @snippet       Video Instead of Images @ Single Product
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 4.0
 * @donate $9     https://tutoraspire.com
 */

add_action( 'woocommerce_before_single_product', 'tutoraspire_show_video_not_image' );
 
function tutoraspire_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', 'tutoraspire_show_product_video', 20 );
   }
}
 
function tutoraspire_show_product_video() {
   echo '';
}

You may also like