Replace Woocommerce product image with video if he field is filled

I’m trying to add a video from youtube etc to the woo product gallery. I’ve got it working with one code snippet but it replaces everything with the video when a video is present. I want to keep the gallery images and replace the product image on the product page only. So basically have a featured image to show on archive and shop page but replace the featured image with a video on the product page and also have gallery images there to view

At the moment I can remove the product image and display a video when one is present, but it shows 2 videos. When no video is present no image at all is shown.

I’ve created a custom field called product_video_embed

This is what I’ve got so far.

function replace_product_thumbnail() { // Remove product images from the shop loop remove_action( 'woocommerce_single_product_image_thumbnail_html', 'woocommerce_template_loop_product_thumbnail', 10 ); // Adding something instead function wc_template_loop_product_replaced_thumb() {         if ( $  wc_product_video = get_post_meta( get_the_ID(), 'product_video_embed', true ) ) {     // Sanitize video URL     $  wc_product_video = esc_url( $  wc_product_video);     // Display video     echo '<div class="images"><div class="ResponsivevideoWrapper">'. wp_oembed_get( $  wc_product_video) .'</div></div>'; } else {     // No video so get thumbnail instead     echo $  woocommerce_single_product_image_thumbnail_html;   } } add_action( 'woocommerce_single_product_image_thumbnail_html', 'wc_template_loop_product_replaced_thumb', 10 ); 

} add_action( ‘woocommerce_init’, ‘replace_product_thumbnail’);