• Resolved damshaw

    (@damshaw)


    Hi,

    I am trying to only show the form if the user has not submitted a rating and if they have submitted only show the results.

    Is this possible?

    Something like this

     if ( 'mrp_rating_result' ) {
         mrp_rating_result();
      } else {
         mr_rating_form();
      }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author dpowney

    (@dpowney)

    Hi damshaw,

    There’s a code snippet you can use in the Pro version, but not the free version as it does have in built functions to checks ratings exist against a user.

    Here’s a code snippet for the Pro version you can use:

    <?php
    // get post id - assumes in WP loop
    global $post;
    $post_id = $post->ID;
    	
    // get default rating form for post, this checks the filter settings, post meta and general settings
    $rating_form_id = MRP_Utils::get_rating_form( $post_id );
    	
    // get current logged in user
    $user_id = 0; // anonymous
    $user = wp_get_current_user();
    if ( $user && $user->ID ) {
    	$user_id = $user->ID;
    }
    	
    // show rating form if user has not yet rated, otherwise show rating item 
    if ( ! MRP_Multi_Rating_API::user_rating_exists( $rating_form_id, $post_id, $user_id ) ) {
    	mrp_rating_form();
    } else {
    	mrp_rating_result();
    }

    Some documentation on template tags in the Pro version here

    Daniel

    • This reply was modified 7 years, 9 months ago by dpowney. Reason: gist embed not working
    • This reply was modified 7 years, 9 months ago by dpowney. Reason: typo in template tag
    • This reply was modified 7 years, 9 months ago by dpowney.
    • This reply was modified 7 years, 9 months ago by dpowney. Reason: update comments
    Plugin Author dpowney

    (@dpowney)

    A couple of other options for the free version if needed.

    1. You can check whether a rating has been submitted recently for that post by checking if the IP address and cookie has already been logged. But this is not reliable and cookies expire. See class-utils.php file and function validate_save_rating_restricton() for an example.

    2. The user id is stored in the rating entry table, so you could also write a database query to check as well.

    Oh and to display the rating form in the free version, it’s easier to use echo do_shortcode( ‘[mr_rating_form]’ );

    Cheers,
    Daniel

    Thread Starter damshaw

    (@damshaw)

    Thanks for the quick response!

    I bought the pro version and it works perfectly.

    Any chance the following feature is int the pipeline would be great to have!

    The ability to have a user just click on a star to automatically submit the rating without the need for the submit button.

    Cheers
    Adam

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide rating form after submit and only show results’ is closed to new replies.