我正在努力通过我的functions.php 正确过滤元数据。
I can get this to work if I edit the meta.php in my child theme with no problem:
(short story - but because I am using Avada Theme - and they change the location of the child theme on an upgrade, I am opting for the functions.php)
我目前正在尝试以这种方式过滤元:
add_filter ('woocommerce_product_meta_start','add_pet_info' );
function add_pet_info($pet_info) {
$string ="Test Text";
return $pet_info . $string; }
And I would like to get this result:
But I just cant get it to work.
我在这里缺少什么想法吗?
Thanks!
woocommerce_product_meta_start https://github.com/woothemes/woocommerce/blob/5893875b0c03dda7b2d448d1a904ccfad3cdae3f/templates/single-product/meta.php#L30不是过滤器。这是一个动作。所以如果你return
的值是,什么都不会发生。这应该在 Woo 打印其任何元之前打印出“测试文本”。
add_action('woocommerce_product_meta_start','add_pet_info' );
function add_pet_info($pet_info) {
_e( "Test Text", "your-textdomain" );
}
不确定您到底要在哪里添加代码,但请记住,您可以将其添加到 WooCommerce 中可用的任何挂钩(或主题中可用的任何挂钩)。
例如,要将测试文本放在产品元下方,您可以将上面的内容修改为以下内容:
add_action('woocommerce_product_meta_end','add_pet_info' );
function add_pet_info($pet_info) {
_e( "Test Text", "your-textdomain" );
}
无论你在哪里看到do_action
您正在查看一个动作挂钩,您可以通过它附加函数add_action()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)