css 将星级评定添加到Woocommerce中的各个产品
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 将星级评定添加到Woocommerce中的各个产品相关的知识,希望对你有一定的参考价值。
<?php
/*-----Source: http://stackoverflow.com/questions/14227121/how-do-you-add-the-star-ratings-for-products-in-woocommerce---*/
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>';
}
?>
/** Source http://www.pootlepress.com/2014/04/100-woocommerce-tips-tricks/
Change the Woocommerce star ratings to show stars rather than theme ratings
**/
.star-rating{float:right;width:80px;height:16px;background:url(images/star.png) repeat-x left 0}
.star-rating span{background:url(images/star.png) repeat-x left -32px;height:0;padding-top:16px;overflow:hidden;float:left}
.hreview-aggregate .star-rating{margin:10px 0 0 0}
#review_form #respond{position:static;margin:0;width:auto;padding:0 0 0;background:transparent none;border:0}
#review_form #respond:after{content:"";display:block;clear:both}
#review_form #respond p{margin:0 0 10px}
#review_form #respond .form-submit input{left:auto}
#review_form #respond textarea{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%}
p.stars:after{content:"";display:block;clear:both}
p.stars span{width:80px;height:16px;position:relative;float:left;background:url(images/star.png) repeat-x left 0}
p.stars span a{float:left;position:absolute;left:0;top:0;width:16px;height:0;padding-top:16px;overflow:hidden}
p.stars span a:hover,p.stars span a:focus{background:url(images/star.png) repeat-x left -16px}
p.stars span a.active{background:url(images/star.png) repeat-x left -32px}
p.stars span a.star-1{width:16px;z-index:10}
p.stars span a.star-2{width:32px;z-index:9}
p.stars span a.star-3{width:48px;z-index:8}
p.stars span a.star-4{width:64px;z-index:7}
p.stars span a.star-5{width:80px;z-index:6}
以上是关于css 将星级评定添加到Woocommerce中的各个产品的主要内容,如果未能解决你的问题,请参考以下文章
如何通过淘汰赛实现 CSS 星级评分
HTML 星级评定
星级评定-Jquery插件
markdown [产品评论]隐藏未评价产品的星级评定。
Woocommerce:将基于键的类添加到'wc_display_item_meta'中的LI中
css WooCommerce添加到购物车按钮CSS