我正在尝试使用挂钩从Woocommerce中的商店/目录页面中删除产品缩略图,然后将其替换为我自己的自定义图像 .
add_action 按预期工作并显示文本,但 remove_action 不会删除产品缩略图 . Here is the page related web site page.
我做错了什么?
以下是我正在使用的代码:
// Remove product images from the shop loop
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
//Add custom code to replace product thumbnail
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumb', 10 );
if ( ! function_exists( 'woocommerce_template_loop_product_thumb' ) ) {
function woocommerce_template_loop_product_thumb() {
echo "testing";
}
}
1 回答
你只需要使用 woocommerce_init 钩子来解决它,这样它就可以了 .
这是代码:
此代码位于活动子主题(或主题)的function.php文件中,或者也可以放在任何插件文件中 .
此代码经过测试且功能齐全 .