Php 删除子主题中的操作问题
在Woocommerce中,我使用了theme,并试图覆盖theme的一些默认函数,但事情并没有像我预期的那样正常工作 例如,我在我的子主题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
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 );
}