SO网友:Md. Mehedi Hassan
用于在代码中显示产品星级
<div class="rating">
<?php add_star_rating(); ?>
</div>
现在转到functios。在主题文件夹中输入php,并插入下面的代码
function add_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>\';
}
add_action(\'woocommerce_after_shop_loop_item\', \'add_star_rating\' );
现在转到样式。css,并在下面插入代码
@font-face {
font-family: star;
src: url("../lets_buy_24/assets/fonts/star.woff") format("woff");
font-style: normal;
font-weight: 400;
}
.star-rating {
/*font-size: .857em;
display: block;
float: none;
float: right;*/
margin: .3em 0;
overflow: hidden;
position: relative;
height: 1em;
line-height: 1;
font-size: 1em;
width: 5.4em;
font-family: star;
}
.star-rating::before {
content: "\\73\\73\\73\\73\\73";
color: #df3737;
float: left;
top: 0;
left: 0;
position: absolute;
}
.star-rating span {
overflow: hidden;
float: left;
top: 0;
left: 0;
position: absolute;
padding-top: 1.5em;
}
.star-rating span::before {
content: "\\53\\53\\53\\53\\53";
top: 0;
position: absolute;
left: 0;
color: #df3737;
}
.star-rating strong {
display: block;
}
你会找到那颗星的。以下路径中的woff文件
wordpress\\wp-content\\plugins\\woocommerce\\assets\\fonts\\star.woff
复制它并有害于您的目录并将其链接到css文件