使用Woocommerce,我使用sober主题,我试图覆盖一些主题的默认功能,但事情并没有像我期望的那样工作。
例如,我在我的孩子主题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_template_single_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 );
}