【发布时间】:2023-04-01 11:56:01
【问题描述】:
我正在尝试显示产品的视频内容。不想禁用产品缩略图,而是在产品库中有可用的视频内容时显示视频内容。视频内容将上传到媒体库和 Youtube。我尝试了几种方法,但都没有奏效。
-
使用 ACF: 我创建了一个自定义字段
product_video,字段类型为oembed。我使用下面的代码。没有错误消息,但视频不显示或显示。
add_action( 'woocommerce_before_shop_loop_item_title', 'action_template_loop_product_thumbnail', 9 );
function action_template_loop_product_thumbnail() {
global $product;
$file = get_field('product_video', $product->get_id());
// $file2 = get_field('product_video_text', $product->get_id());
if( isset($file['url']) && ! empty($file['url']) ) {
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
echo '<video width="200" muted loop autoplay src="' . $file['url'] . '"></video>';
// echo $file2 ;
}
}
为什么不显示?
2)Use product video plugin. 它可以在前端工作,但文件afpv_front.js 中有错误Uncaught TypeError: jQuery(...).slick is not a function。我将slick.js 排入队列,认为它会纠正问题,但事实并非如此。它带来了更多的错误。
function enqueue_slick() {
if(is_shop() || is_product() || is_product_category() ) {
wp_enqueue_script( 'slick-css', get_stylesheet_directory_uri() . '/assets/js/slick/slick.css'); //do not mind the relevancy of the folder name, just a quick fix for now
wp_enqueue_script( 'slick-theme-css', get_stylesheet_directory_uri() . '/assets/js/slick/slick-theme.css');
wp_enqueue_script( 'slick-min-css', get_stylesheet_directory_uri() . '/assets/js/slick/slick.min.js');
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_slick' );
它会产生如下错误:
Uncaught SyntaxError: expected expression, got '.' 来自 slick.cssUncaught SyntaxError: illegal character U+0040 来自 slick-theme.css:1Error: Promised response from onMessage listener went out of scope
为产品添加视频内容的正确方法是什么?
【问题讨论】:
标签: php jquery wordpress woocommerce advanced-custom-fields