Арт*_*нко 3 php wordpress product woocommerce hook-woocommerce
我已经从Shophistic Lite主题创建了子主题。
我想删除子主题中的一个动作。
// wp-content\plugins\woocommerce\templates\content-product.php ...
/**
* woocommerce_shop_loop_item_title hook.
*
* @hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item_title hook.
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item hook.
*
* @hooked woocommerce_template_loop_product_link_close - 5
* @hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
...
Run Code Online (Sandbox Code Playgroud)
// \wp-content\themes\shophistic-lite\framework\functions\woocommerce_support.php
...
/**
* Adds the Switch View buttons
*/
function shophistic_lite_show_attribute() {
...
}
add_action( 'woocommerce_after_shop_loop_item_title', 'shophistic_lite_show_attribute', 15 );
...
Run Code Online (Sandbox Code Playgroud)
// \wp-content\themes\shophistic-lite-child\functions.php
...
function remove_functions() {
remove_action( 'woocommerce_after_shop_loop_item_title', 'shophistic_lite_show_attribute', 15 );
}
add_action('woocommerce_after_shop_loop_item' , 'remove_functions' );
...
Run Code Online (Sandbox Code Playgroud)
我通过这篇文章做到了:https : //code.tutsplus.com/tutorials/a-guide-to-overriding-parent-theme-functions-in-your-child-theme--cms-22623
但它不起作用为了我。该shophistic_lite_show_attribute函数仍在执行中。
请帮我解决这个问题。
您应该尝试使用'init'钩子代替您的删除操作,以便在初始化时将其删除:
function child_custom_actions() {
remove_action( 'woocommerce_after_shop_loop_item_title', 'shophistic_lite_show_attribute', 15 );
}
add_action( 'init' , 'child_custom_actions' );
Run Code Online (Sandbox Code Playgroud)
此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。
此代码经过测试并有效 (见下文)。
与您的评论相关的更新:
我已将您的主题上传Shophistic Lite到测试服务器,并创建了一个子主题。
我已经临时变化的功能上的主旋律中woocommerce_support.php的文件,使其显示的东西,没有任何特殊的设置需要(保存)是这样的:
/**
* Adds the Switch View buttons
*/
function shophistic_lite_show_attribute() {
echo '<p>BLA BLA</p>';
}
add_action( 'woocommerce_after_shop_loop_item_title', 'shophistic_lite_show_attribute', 15 );
Run Code Online (Sandbox Code Playgroud)
它在商店页面上显示:
然后我function.php在子主题的文件中添加了上面第一个片段的代码(与您使用“init”钩子尝试过的相同),它完美地工作,删除了“BLA BLA”。
因此,您可能正在尝试删除此钩子未生成的其他内容……