How To Add Video In Woocommerce Product Gallery Without Plugin

Incorporating videos into your product gallery on WooCommerce is an effective way to display your products and offer additional details to your customers. This guide will walk you through the steps of adding videos to your WooCommerce product gallery without the use of any plugins.

Step 1: Preparing Your Video

Before we begin, it’s important to have your video ready. Make sure your video is in a compatible format, such as MP4 or WebM, and that it is optimized for web viewing. You can use tools like HandBrake or FFmpeg to convert and optimize your video if needed.

Step 2: Uploading Your Video

Now that you have your video ready, it’s time to upload it to your WooCommerce product gallery. Login to your WordPress admin dashboard and navigate to the product you want to add the video to. Scroll down to the Product Gallery section.

Click on the “Add Videos” button and select the video file from your computer. Once the upload is complete, you will see the video thumbnail in the product gallery.

Step 3: Adding the Video to the Product Gallery

After uploading the video, you need to add it to the product gallery. By default, WooCommerce only shows the images in the product gallery. To include the video, we need to modify the code.

Open the product-edit.php file located in the WooCommerce plugin directory. Search for the code that begins with “$attachment_ids = get_posts( ...“. Add the following code just before that line:

$attachment_ids[] = get_post_meta( get_the_ID(), '_product_video', true );

Save the file and refresh the product edit page in your WordPress admin dashboard. You will now see the video included in the product gallery.

Step 4: Displaying the Video on the Product Page

Now that you have added the video to the product gallery, you need to display it on the product page. Open the single-product.php file located in your WooCommerce theme directory.

Find the code that displays the product gallery. It should look something like this:

<div class="woocommerce-product-gallery">
<figure class="woocommerce-product-gallery__wrapper">
<!-- product gallery images go here -->
</figure>
</div>

After the opening <div> tag, add the following code:

<div class="woocommerce-product-gallery__video">
<div class="woocommerce-product-gallery__video-wrapper">
<!-- video player goes here -->
</div>
</div>

Save the file and refresh the product page on your website. You will now see the video displayed alongside the product gallery images.

Conclusion

Adding videos to your WooCommerce product gallery without using a plugin is a great way to enhance the shopping experience for your customers. By following the steps outlined in this article, you can easily showcase your products with videos and provide more information to potential buyers. Happy selling!