I have a basic question that has always stumped me. I’m trying to move the Star Rating into the comment meta, which will help me style it. Here’s the template file review.php
section:
<div class="comment-text">
<?php
/**
* The woocommerce_review_before_comment_meta hook.
*
* @hooked woocommerce_review_display_rating - 10 //Want to unhook this.
*/
do_action('woocommerce_review_before_comment_meta', $comment);
/**
* The woocommerce_review_meta hook.
*
* @hooked woocommerce_review_display_meta - 10
*/
do_action('woocommerce_review_meta', $comment);
do_action('woocommerce_review_before_comment_text', $comment);
/**
* The woocommerce_review_comment_text hook
*
* @hooked woocommerce_review_display_comment_text - 10
*/
do_action('woocommerce_review_comment_text', $comment);
do_action('woocommerce_review_after_comment_text', $comment);
?>
</div>
I was thinking I could add the following to my functions.php:
remove_action('woocommerce_review_display_rating', 10);
And add it back in the review-meta.php, but I can’t remove / unhook the star rating. What am I doing wrong?
2 Answers
You need to unhook the function from that action specifically:
remove_action( 'woocommerce_review_before_comment_meta',
'woocommerce_review_display_rating', 10 );
(e.g. look for the opposite add_action() line in includes/wc-template-hooks.php)
You’ll also need to make sure that this is run after WooCommerce has loaded and added the action you’re about to remove, e.g. place this in a plugins_loaded hook:
function unhook_display_rating() {
remove_action( 'woocommerce_review_before_comment_meta',
'woocommerce_review_display_rating', 10 );
}
add_action( 'plugins_loaded', 'unhook_display_rating', 10, 0 );