woocommerce вывод отзывов на главной

Если необходимо вывести  определенное количество отзывов в определенном месте шаблона или на определенной странице, то можно воспользоваться следующим кодом:

function get_woo_reviews()
{
    $comments = get_comments(
        array(
            'status'      => 'approve',
            'post_status' => 'publish',
            'post_type'   => 'product',
        )
    ); 
    shuffle($comments);
    $comments = array_slice( $comments, 0, 5 );
    $html = '<ul>';
    foreach( $comments as $comment ) :
        $html .= '<li><h2>'.get_the_title( $comment->comment_post_ID ).'</h2>';
        $html .= '<p>' .$comment->comment_content.'</p>';
        $html .= "<p>Posted By :".$comment->comment_author." On ".$comment->comment_date. "</p></li>";
    endforeach;
    $html .= '</ul>';
    ob_start();
    echo $html;
        $html = ob_get_contents();
    ob_end_clean();

    return $html;
}
add_shortcode('woo_reviews', 'get_woo_reviews');

И потом использовать:

echo do_shortcode( "[woo_reviews]" );

 

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *