Skip to content

Instantly share code, notes, and snippets.

@gnikolopoulos
Last active August 7, 2018 23:25
Show Gist options
  • Save gnikolopoulos/ed9907fc20598bd73a44 to your computer and use it in GitHub Desktop.
Save gnikolopoulos/ed9907fc20598bd73a44 to your computer and use it in GitHub Desktop.
[Woocommerce] Add video as featured image for products
<?php
// Display product video instead of image/slider
function woocommerce_show_product_images() {
// Get video and display
if ( $video = get_post_meta( get_the_ID(), 'product_post_video', true ) ) {
// Sanitize video URL
$video = esc_url( $video );
// Display video
echo '<div class="images"><div class="responsive-video-wrap">'. wp_oembed_get( $video ) .'</div></div>';
} else {
// No video defined so get thumbnail
wc_get_template( 'single-product/product-image.php' );
}
}
?>
@leandroprz
Copy link

I just read your article here, and I have a quick question: how do I add a new custom field name so I cant put the video URL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment