Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Woocommerce归档页面中显示产品星级并低于价格_Php_Wordpress_Templates_Woocommerce_Hook Woocommerce - Fatal编程技术网

Php 在Woocommerce归档页面中显示产品星级并低于价格

Php 在Woocommerce归档页面中显示产品星级并低于价格,php,wordpress,templates,woocommerce,hook-woocommerce,Php,Wordpress,Templates,Woocommerce,Hook Woocommerce,在woocommerce档案页面中,我想将评级移到价格下 可能吗?我怎样才能做到 以下是我想要的: 感谢您的帮助 My以下功能将在Woocommerce存档页面中将评级移到低于价格的位置: add_action('woocommerce_after_shop_loop_item_title','change_loop_ratings_location', 2 ); function change_loop_ratings_location(){ remove_action('wooco

在woocommerce档案页面中,我想将评级移到价格下

可能吗?我怎样才能做到

以下是我想要的:

感谢您的帮助


My

以下功能将在Woocommerce存档页面中将评级移到低于价格的位置:

add_action('woocommerce_after_shop_loop_item_title','change_loop_ratings_location', 2 );
function change_loop_ratings_location(){
    remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_rating', 5 );
    add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_rating', 15 );
}
代码进入活动子主题(或活动主题)的function.php文件。测试和工作


添加以获取评级计数:

add_filter( 'woocommerce_product_get_rating_html', 'loop_product_get_rating_html', 20, 3 );
function loop_product_get_rating_html( $html, $rating, $count ){
    if ( 0 < $rating && ! is_product() ) {
        global $product;
        $rating_cnt = array_sum($product->get_rating_counts());
        $count_html = ' <div class="count-rating">' . $rating_cnt .'</div>';

        $html       = '<div class="container-rating"><div class="star-rating">';
        $html      .= wc_get_star_rating_html( $rating, $count );
        $html      .= '</div>' . $count_html . '</div>';
    }
    return $html;
}
add_filter('woocommerce_product_get_rating_html','loop_product_get_rating_html',20,3);
函数循环\产品\获取\评级\ html($html,$rating,$count){
如果(0<$rating&!is_product()){
全球$产品;
$rating\u cnt=array\u sum($product->get\u rating\u counts());
$count_html='.$rating_cnt';
$html='';
$html.=wc_get_star_rating_html($rating,$count);
$html.=''.$count_html';
}
返回$html;
}
需要一些额外的CSS样式(可能是html结构更改)


代码进入活动子主题(或活动主题)的function.php文件。测试和工作。

您的代码工作正常id您看到也有计数数字我需要它以同一行显示在评论中非常感谢您的帮助请少帮助谢谢您的帮助me@R.K.Bhardwaj-上述答案有效,但是,您是如何让评分计数显示为与评论星相同的行的?如果没有可用的评分,但我仍然希望显示值为0的星。有可能吗?@FatemaT.Zuhora…有可能将代码行:
if(0<$rating&&!Is_product()){
替换为以下代码行:
if(0)即使OP没有给出任何代码,这个问题也不会太大。工作答案是5行代码。所以请考虑重新打开这个线程,因为这个问题/答案对社区是有用的。