Pratik Bhatt

How to replace the product gallery with product video in woocommerce

I am presenting here a code methodology  that will be used to replace the product gallery in woocommerce with a custom product video or a  video from youtube.

For implementing the same you need to add the following code in your theme’s functions.php file or you can also add the same into your custom plugin.

 

add_action( 'woocommerce_before_single_product', ‘pkb_replace_vid_with_progal’ );

function pkb_replace_vid_with_progal () {
  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', 'pkb_show_product_video', 20 );
}

function pkb_show_product_video() {
  echo '<div class="woocommerce-product-gallery">'; 
  echo '<iframe title="YouTube video player" src="https://www.youtube.com/embed/K4TOrB7at0Y" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>';   
  echo '</div>'; 
}

Hence using the above script in your functions.php file you will be able to replace the woocommerce product thumbnail gallery with custom video.

Leave a Comment