Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除子主题中的操作问题_Php_Wordpress_Woocommerce_Product_Hook Woocommerce - Fatal编程技术网

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

Php 删除子主题中的操作问题,php,wordpress,woocommerce,product,hook-woocommerce,Php,Wordpress,Woocommerce,Product,Hook Woocommerce,在Woocommerce中,我使用了theme,并试图覆盖theme的一些默认函数,但事情并没有像我预期的那样正常工作 例如,我在我的子主题functions.php中写了以下代码块: function remove_parent_theme_function() { remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 1

在Woocommerce中,我使用了theme,并试图覆盖theme的一些默认函数,但事情并没有像我预期的那样正常工作

例如,我在我的子主题
functions.php
中写了以下代码块:

function remove_parent_theme_function() {
    remove_action( 'woocommerce_single_product_summary',
                   'woocommerce_template_single_rating', 15 );
}
add_action('after_setup_theme', 'remove_parent_theme_function');
我希望从上面的代码块中删除产品页面中的评级部分,但事实并非如此


如何覆盖父主题操作?

模板功能
woocommerce\u template\u single\u rating
的优先级为
10
(而不是
15
)…请尝试以下操作:

add_action('woocommerce_single_product_summary', 'remove_single_rating', 2 );
function remove_single_rating() {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
}
此代码位于活动子主题(或主题)的function.php文件中。它应该有效


或者,如果您的主父主题对此进行了一些更改,优先级为
15
,请使用:

add_action('woocommerce_single_product_summary', 'remove_single_rating', 2 );
function remove_single_rating() {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 15 );
}

add_action('init', 'remove_single_rating', 2 );
function remove_single_rating() {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 15 );
}