راکت

نمایش ستاره امتیاز برای همه کالاها در ووکامرس

2 پاسخ

سلام ، من میخوام داخل ووکامرس ستاره امتیاز دهی رو برای همه کالاها نمایش بده چه اون کالاهایی که امتیازی براشون ثبت شده چه اونایی که ثبت نشده کدش رو از اینترنت پیدا کردم ولی یه اشکالاتی داشت. مثلا اونایی که امتیاز داشتن رو دو بار نمایش میداد . کدش هم همینه :

add_action('woocommerce_after_shop_loop_item_title', 'njengah_woocommerce_template_single_excerpt', 5);
function njengah_woocommerce_template_single_excerpt() {
  // The "echo '</a>';" line below MAY BE needed to close the anchor tag (link/href) added for product images
    // That way, we can use a different (custom) link for our star ratings and star rating text
    // Comment this out if it is not applicable in your case.
    echo '</a>';
        global $product;
    $rating = $product-&gt.get_average_rating();
    if ( $rating > 0 ) {
        $title = sprintf(__( 'Rated %s out of 5:', 'woocommerce' ), $rating);
    } else {
        $title = 'Rate this product:';
        $rating = 0;
    }
    $rating_html  = '</a><a href="https://roocket.ir/' . get_the_permalink() . '#respond"><div class="star-rating ehi-star-rating"><span style="width:' . (( $rating / 5 ) * 100) . '%"></span></div><span style="font-size: 0.857em;"><em><strong>' . $title . '</strong></em></span></a>';
    echo $rating_html;
     // Now we display the product short description. This is optional.
    wc_get_template('single-product/short-description.php'); 
ثبت پرسش جدید

پاسخ‌ها

2
حامد شادمان
حامد شادمان
@HamedShadman

تخصص: طراحی وب سایت و فروشگاه اینترنتی

ووکامرس به صورت پیشفرض امکان ستاره دادن به محصولات براش فعال هست و نیاز به کدی نداره مگر اینکه از تنظیمات ووکامرس بخش امتیاز دهی رو غیرفعال کرده باشید.

robinashly
robinashly
@robinashly

کدش رو پیدا کردم
ممنون از پاسختون ولی میخواستم برای همه محصولات رو نمایش بده چه اونایی که امتیاز دارن و چه ندارن، کدش رو پیدا کردم .

remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );

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>';
}

شاید پاسخ شما همین‌جا باشد

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام