php – Replace the image of a product with its video in the shop page
Question
I am trying to replace the image of the products with its video in the shop page.
I tried this one
add_action( 'init', 'get_product_video_url' );
function get_product_video_url() {
$product_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids'
) );
foreach ( $product_ids as $product_id ) {
$video_url = get_post_meta( $product_id, 'video_url', true );
echo '<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>';
echo '<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>';
echo "<script type=\"text/javascript\">
jQuery(document).ready(function($){
$(\"<video playsinline=\"playsinline\" autoplay=\"autoplay\" loop=\"loop\" muted=\"muted\" preload=\"metadata\"><source src=\"'$video_url'" type=\"video/mp4\"></video>\").insertAfter(\"ul.products li.product .product-thumbnail .woocommerce-loop-product__link\"); });
</script>";
}
}
but I can’t get it to work.
0
7 months
2022-10-31T18:57:58-05:00
2022-10-31T18:57:58-05:00 0 Answers
0 views
0
Leave an answer