Last active
August 7, 2018 23:25
-
-
Save gnikolopoulos/ed9907fc20598bd73a44 to your computer and use it in GitHub Desktop.
[Woocommerce] Add video as featured image for products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?