• Hello,

    I am trying to show all the reviews of the loged in user in a template. Is there any script for that or could you point me to the right direction from where to start?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lesanis

    (@lesanis)

    I have found from an old thread this shortcode that shows all the reviews

    add_shortcode( 'reviews', 'show_reviews' );
    
    function show_reviews() {?> <?php
        $args = array ('post_type' => 'product');
        $comments = get_comments( $args );
        wp_list_comments( array( 'callback' => 'woocommerce_comments' ), $comments);
    ?> <?php
    }

    but how could I make it show only logged in user’s reviews? I have tried the following

    add_shortcode( 'my_reviews', 'show_my_reviews' );
    
    function show_my_reviews() {?> <?php
        $args = array ('post_type' => 'product',
    				 'user_id' => $current_user->ID );
        $comments = get_comments( $args );
        wp_list_comments( array( 'callback' => 'woocommerce_comments' ), $comments);
    ?> <?php
    }

    but didn’t work. Could you please help me?

    Thank you!

    • This reply was modified 7 years, 9 months ago by lesanis.

    You should set the variable $current_user before you use it:
    $current_user = wp_get_current_user();

    ?> <?php is redundant.

    • This reply was modified 7 years, 9 months ago by Majeed Raza.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Reviews by user id’ is closed to new replies.