2017-09-13 62 views
1

我正在尝试在单个产品页面(woocommerce)的库下添加视频。当我添加钩子“woocommerce_product_thumbnails”时,没有任何反应。我注意到在woocommerce钩子的视觉指南中,它说“woocommerce_product_thumbnails(可能不适用于WC 3.0以后的新产品库)”。是否有解决此问题的方法?woocommerce_product_thumbnails挂钩现已折旧?什么是解决方法?

这里是我当前的代码:

add_action('woocommerce_product_thumbnails', 'add_product_video'); 

function add_product_video(){ 

    echo "<iframe width='560' height='315' src='https://www.youtube.com/embed/JHN7viKRxbQ' frameborder='0' allowfullscreen></iframe>"; 

} 
+0

https://stackoverflow.com/questions/43241524/how-to-make-woocommerce-3-0-single-image-gallery-so-it-is-like-version-2-x/43241525#43241525 – LoicTheAztec

+1

如果您正在使用'product-image,那么该钩子仍然存在于[source](https://github.com/woocommerce/woocommerce/blob/103f674d185c6aff3ed18c9762825675f61d3151/templates/single-product/product-image.php#L60)中。 php'模板任何地方。 – helgatheviking

回答

2

可以使用do_action()功能,使其在其他可能的方式。在您的woocommerce文件夹中浏览到该路径:woocommerce/templates/single-product/tabs/tabs.php

上线22号,添加:

do_action("woocommerce_add_my_video"); 

而且你的主题的functions.php里面,放:

add_action('woocommerce_add_my_video', 'add_product_video'); 
function add_product_video(){ 

    echo "<iframe width='560' height='315' src='https://www.youtube.com/embed/JHN7viKRxbQ' frameborder='0' allowfullscreen></iframe>"; 

} 

见参考链接这里:Template Structure + Overriding Templates via a Theme

+0

**好的选择! + 1 ** ...不建议编辑插件文件。相反,你应该在你的答案中加入一些更多的细节:[** Template Structure + Overriding Templates via a Theme **](https://docs.woocommerce.com/document/template-structure/)链接作为参考。 – LoicTheAztec

+0

为了扩展LoicTheAztec说这个答案只是一个临时的解决方案,因为只要WooCommerce更新您对tabs.php所做的更改就会被撤销,因此建议您通过将WooCommerce模板复制到主题或子主题中来覆盖WooCommerce模板。在附注中,有很多可用的钩子,所以不需要创建自己的钩子,为什么不使用'woocommerce_before_single_product_summary'之类的东西[如这里所示](https://github.com/woocommerce/woocommerce/blob/master /templates/content-single-product.php)。 – Kodaloid

+0

[通过主题覆盖Woocommerce模板](https://docs.woocommerce.com/document/template-structure/)是WooCommerce插件的主要功能之一,用于进行自定义,因为它们很少发生更改,并且不会被插件更新。确保在可能的情况下使用可用的钩子是一种更好的方式,但有时它们也可能会被弃用... – LoicTheAztec

相关问题