Php 删除子主题中的父主题操作

Php 删除子主题中的父主题操作,php,wordpress,woocommerce,product,hook-woocommerce,Php,Wordpress,Woocommerce,Product,Hook Woocommerce,我已经从Shophistic Lite主题创建了子主题 我想删除子主题中的操作 //wp content\plugins\woocommerce\templates\content product.php /\wp content\themes\shophistic lite\framework\functions\woocommerce\u support.php ... /** * Adds the Switch View buttons */ function shophistic_

我已经从
Shophistic Lite
主题创建了子主题

我想删除子主题中的操作

//wp content\plugins\woocommerce\templates\content product.php

/\wp content\themes\shophistic lite\framework\functions\woocommerce\u 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 );
...
...
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' );
...
/\wp content\themes\shophistic lite child\functions.php

...
/**
 * Adds the Switch View buttons
 */
function shophistic_lite_show_attribute() {
...
}
add_action( 'woocommerce_after_shop_loop_item_title', 'shophistic_lite_show_attribute', 15 );
...
...
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' );
...
我通过这篇文章做到了: 但这对我没用。
shophistic\u lite\u show\u属性
函数仍在执行


请帮助我解决此问题。

对于删除操作,您应该尝试使用
'init'
钩子,以便在初始化时删除它:

function child_custom_actions() {
    remove_action( 'woocommerce_after_shop_loop_item_title', 'shophistic_lite_show_attribute', 15 );
}
add_action( 'init' , 'child_custom_actions' );
这段代码位于活动子主题(或主题)的function.php文件或任何插件文件中

此代码经过测试并正常工作(见下文)


与您的评论相关的更新:

我已将您的主题
Shophistic Lite
上传到测试服务器中,并创建了一个子主题

我临时更改了
woocommerce\u 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 );
/**
*添加“切换视图”按钮
*/
函数shophistic_lite_show_属性(){
回声“BLA-BLA

”; } 添加动作('woocommerce'在'shop'循环'item'标题之后,'shophistic'精简'show'属性',15);
它会显示在商店页面上,如下所示:

然后我在子主题的
function.php
文件中添加了上面第一个代码片段的代码(与您使用“init”钩子尝试的代码相同),它工作得非常好,删除了“BLA-BLA”


因此,可能您正在尝试删除此钩子未生成的其他内容…

在我的示例中,我尝试从单个产品页面中删除相关的产品部分。它不是默认的相关产品部分,它特定于我的主题(因此我必须从父主题中删除操作)

使用
wp\u-loaded
hook工作正常,而上面提到的
init
hook不工作

最后,我的孩子主题中的代码运行良好:

function child_custom_actions() {
    remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products', 20 );
}
add_action( 'wp_loaded' , 'child_custom_actions' );

警告:
woocommerce\u-after\u-single\u-product
hook不是woocommerce相关产品部分的默认hook,它是特定于我的主题的,您可能需要使用
woocommerce\u-after\u-single\u-product\u-summary
hook。

I我的问题所附的教程是:>“…您需要将此函数附加到一个钩子,该钩子将在父主题函数附加到的钩子之后触发。。。“我在上下文中这个函数的意思是
remove\u action
,顺便说一下,我尝试使用
init
hook-它不起作用。好的,我正在等待你的答案。我尝试再次使用
init
hook,但没有结果。@АаёМааааааааааааа。