1

i am new WooCommerce, i am having one issue for product single page. which is rating and sharing not showing. i want to show in single page rating, sharing and review count number.

bellow content-single-product.php code

<div class="summary entry-summary">

    <?php
        /**
         * woocommerce_single_product_summary hook
         *
         * @hooked woocommerce_template_single_title - 5
         * @hooked woocommerce_template_single_rating - 10
         * @hooked woocommerce_template_single_price - 10
         * @hooked woocommerce_template_single_excerpt - 20
         * @hooked woocommerce_template_single_add_to_cart - 30
         * @hooked woocommerce_template_single_meta - 40
         * @hooked woocommerce_template_single_sharing - 50
         */
        do_action( 'woocommerce_single_product_summary' );
    ?>



</div>

this way rating and share not coming. but this is default code.

i do that in my function for reorder hooked

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 10 );
    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 20 );
    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 40 );
    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

still now showing. i check in generate html code. nothing i see class/id/div rating and sharing html

but my shop(product) page thumbnail rating show. i add costume start rating which is

add_action('woocommerce_after_shop_loop_item', 'get_star_rating' );
function get_star_rating()
{
    global $woocommerce, $product;
    $average = $product->get_average_rating();

    echo '<div class="star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>';
}

this is working find one product page. i want add this start rating and shearing button in my single page and want to review count .. example attached image enter image description here

i think for sharing for have plugins. if you guys any recommended plugins for sharing please share with me.

1 Answer 1

1

I try to give you some cleanup solution which is basic code setup.

For social share: See plugin Social Sharing Toolkit Which is easy sharing and connecting on social networks. Display on posts or use widgets or shortcode. Also Twitter name/hashtag to link converter.

use do_shortcode('[social_share]') for display social share anywhere on site. In woocoomrce Product page use this code in content-single-product.php file.

For Star rating: There is a sort logic here for if you need star rating at your single product, then you will need to do template editing.

Edit your /x/woocommerce/single-product/rating.php and add this code before ?>

GLOBAL $product; echo '<div class="star-rating-container aggregate">' . $product->get_rating_html() . '</div>';

This will add star rating below product title. See more at here.

With above solution, I'm not sure about that so if you want to go with your risk.

You can put this into your themes functions.php file:

add_action('woocommerce_after_shop_loop_item', 'my_print_stars' );


function my_print_stars(){
    global $wpdb;
    global $post;
    $count = $wpdb->get_var("
    SELECT COUNT(meta_value) FROM $wpdb->commentmeta
    LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
    WHERE meta_key = 'rating'
    AND comment_post_ID = $post->ID
    AND comment_approved = '1'
    AND meta_value > 0
");

$rating = $wpdb->get_var("
    SELECT SUM(meta_value) FROM $wpdb->commentmeta
    LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
    WHERE meta_key = 'rating'
    AND comment_post_ID = $post->ID
    AND comment_approved = '1'
");

if ( $count > 0 ) {

    $average = number_format($rating / $count, 2);

    echo '<div class="starwrapper" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">';

    echo '<span class="star-rating" title="'.sprintf(__('Rated %s out of 5', 'woocommerce'), $average).'"><span style="width:'.($average*16).'px"><span itemprop="ratingValue" class="rating">'.$average.'</span> </span></span>';

    echo '</div>';
    }

}

Note that you may need to change 'woocommerce_after_shop_loop_item' to a different hook depending on your design and where exactly you want the stars to show up.

For more detail please check wooCodex.

Hope this help you well!

3
  • thanks for your reply. i tried both code for rating but none is showing :( no idea why. do you any other soultion or is there any setting which i am missing. i already google long time but not getting any solution . exmple this is nice way flatsome.uxthemes.com/product/brooklyn-long-sleeve-sweater
    – pagol007
    Commented Feb 1, 2016 at 16:29
  • thanks. code is working fine. i found out what's the problem. problem was may be data. when i insert product again then it is working fine. but i dont know why it was. i was dump data from another live website
    – pagol007
    Commented Feb 2, 2016 at 7:08
  • Cheers. Glad to help! Commented Feb 2, 2016 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.