Enable reviews with stars using WooCommerce


Same problem here, trying to enable ratings with stars, but just usual comment form appears.. maybe I have to add theme support..



add_action('beans_comment_header_before_markup', function(){
    if(is_product()){
        global $comment;
        echo wc_get_rating_html(get_comment_meta( $comment->comment_ID, 'rating', true ), 1);
    }
});

This is a good start


And to get the rating selector into the comment form itself, you can do this:


add_action('beans_comment_form[_comment]_after_markup', function(){ ?>
<label for="rating">Rating</label>
    <div class="element-select">
        <span></span>
        <select name="rating" id="rating">
            <option value="">&ndash;</option>
            <option value="5">5</option>
            <option value="4">4</option>
            <option value="3">3</option>
            <option value="2">2</option>
            <option value="1">1</option>
        </select>
    </div>       
<?php });

The above can probably be replaced by a woocommerce function that is generating that actual markup/output. You can then amend the rest of the form using markup API.


And here are the replacement labels, to remove the use of 'comment'

add_filter( 'beans_comments_title_text_output', function(){
    return get_comments_number() . ' Reviews';
});

add_filter( 'beans_comment_form_title_text_output', function(){
    return 'Please Leave a review';
});
add_filter( 'beans_no_comment_text_output', function(){
    return 'No one has reviewed yet';
});

add_filter('beans_comment_form_submit_text_output', function(){
    return 'Post Review';
});

Sorry I missed the placeholder of the actual review/comment textarea

add_filter('beans_comment_form_legend_text[_comment]_output', function(){
    return 'Review';
});

YEAH! Thank Carl, this work great!

There is a way to unload the comment form (not hide but completely disable) the comment form where you don need it?

Thank you!


No worries! Sorry for delays

beans_remove_action( 'beans_comments_template' );

As a sidenote I recently had to "move" reviews into a custom woocommerce tab.

I'm not sure if this is the best way of achieving this but this was the process, in combination with previous relabelling and additions

beans_remove_action( 'beans_comments_template' );
add_action('custom_reviews_prepend_markup', 'beans_comments_template');

add_filter( 'woocommerce_product_tabs', 'add_review_tab' );
function add_review_tab( $tabs ) { // Adds the new tab
    $tabs['review_tab'] = array(
        'title'     => __( 'Reviews', 'woocommerce' ),
        'priority'  => 10,
        'callback'  => 'custom_review_tab'
    );
    return $tabs;
}

function custom_review_tab() {
    beans_open_markup_e( 'custom_reviews', 'div', array( 'class' => 'reviews') );
    beans_close_markup_e( 'custom_reviews', 'div' );

}

Same here, want to add the review section in a custom tab.

Really thank you!

Write a reply

Login or register to write a reply, it's free!