Last active
February 6, 2019 11:15
-
-
Save mmilosheski/006adef3e9dbc0033cd5c0c062ea6336 to your computer and use it in GitHub Desktop.
removing the featured product image, and replacing it with a featured video, this code uses ACF (configured upload field for product post type, to return the URL of the upload)
This file contains hidden or 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
// just place this code to the functions.php file of your active theme (child or parent) | |
add_filter( 'woocommerce_single_product_image_html', 'remove_featured_image', 10, 3 ); | |
function remove_featured_image( $html, $attachment_id, $post_id ) { | |
// this is a ACF upload field, configured to return the upload URL (location) and assigned to product post type | |
// `upload_product_video` is the slug of the ACF field | |
$product_video_url = get_field( 'upload_product_video', $post_id ); | |
// we replace the original featured image of the product, with a video | |
if ( '' != $product_video_url ) { | |
return '<style>video#product-video { display: block; width: 100%; height: auto; box-shadow: none; }</style><video id="product-video" width="375" height="375" controls><source src="' . $product_video_url . '" type="video/mp4"><source src="' . $product_video_url . '" type="video/ogg">Your browser does not support HTML5 video.</video>'; | |
} else { | |
return $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment