WordPress Local Business Reviews with SEO Rich Snippets

Business Address in Custom FieldsA previous post covered the setting up of a WordPress reviews feature with the WPCR plugin. This tutorial will explain how to add the following features:

We can add this via custom fields, which we first need to call in the wp-customer-reviews.php after making the minor changes from the WP Customer Reviews setup tutorial. Don't worry, if this becomes too confusing, the updated script can be downloaded by the end of this tutorial. Remember to just use the custom fields we use in this tutorial if you decide to use the file raw.

WPCR Unique Business Address Per Review Page

The way the business address is displayed can be controlled from the get_options() functions $default_options array. The variables are the following:

  • show_hcard - Make the hcard hidden or visible (Parameters True or False)
  • show_hcard_on - Whether to display the hcard and where to display them (0 = Never, 1 = All, 2 = Homepage and Review Page, 3 = Reviews Page).

For the purpose of the this tutorial, we display the hcard on the review pages ('show_hcard_on'=>3) and keep it hidden ('show_hcard'=>0). This way, you can display the address elsewhere without being limited to the plugin footer or show it twice.

Dynamically Adding Address from Custom Fields

Now we grab the address from custom fields within your post, so you would require one custom field per address section (see custom field example). In the wp-customer-reviews.php file, find the following lines in the function aggregate_footer() function:

if ($show) { /* we append like this to prevent newlines and wpautop issues */
                
                $aggregate_footer_output = '<div id="' . $div_id . '" class="vcard">';
                $aggregate_footer_output .= '<a class="url fn org">options['business_url'] . '">' . $this->options['business_name'] . '</a><br />';
                
                if (

Then, we add the call for the custom fields of the current post by adding the following:

if ($show) { /* we append like this to prevent newlines and wpautop issues */
			global $post;
                        $this->options['business_street'] = get_post_meta($post->ID, 'mb_streetaddress', true); 
			$this->options['business_city'] = get_post_meta($post->ID, 'mb_city', true);   
			$this->options['business_state'] = get_post_meta($post->ID, 'mb_state', true); 
			$this->options['business_zip'] = get_post_meta($post->ID, 'mb_zip', true); 
			$this->options['business_country'] = 'USA';
			$this->options['business_url'] = get_post_meta($post->ID, 'mb_business_url', true);    
			$this->options['business_name'] = get_post_meta($post->ID, 'mb_business_name', true); 
			$this->options['business_phone'] = get_post_meta($post->ID, 'mb_business_phone', true); 
                $aggregate_footer_output = '<div id="' . $div_id . '" class="vcard">';
                $aggregate_footer_output .= '<a class="url fn org">options['business_url'] . '">' . $this->options['business_name'] . '</a><br />';
                
                if (

So by naming a custom field in a post mb_streetaddress, its value will show up $this->options['business_street'] in the review plugins front-end. By assigning the value of 'USA' to $this->options['business_country'], we will no longer need this as a custom field.

Different Email Notification after Review Post

The feature to notify a different e-mail after a review has been posted can be implemented via custom fields as well. In the function add_review($pageID), the following lines send out the e-mail to the admin (you can also change the e-mail message here):

$wpdb->query($query);

        $admin_link = get_admin_url().'admin.php?page=wpcr_view_reviews';
        $admin_link = "Link to admin approval page: $admin_link";

        @wp_mail(get_bloginfo('admin_email'), "WP Customer Reviews: New Review Posted on " . date('m/d/Y h:i'), "A new review has been posted for " . $this->options['business_name'] . " via WP Customer Reviews. nnYou will need to login to the admin area and approve this review before it will appear on your site.nn{$admin_link}");

        /* returns false for no error */
        return array(false, '
Thank you for your comments. All submissions are moderated and if approved, yours will appear soon.
'); }

By default, the plugin uses get_bloginfo('admin_email'), which we can replace with the value of a custom field. In this case, we call a custom field named mb_email and replace the default like this:

$wpdb->query($query);

        $admin_link = get_admin_url().'admin.php?page=wpcr_view_reviews';
        $admin_link = "Link to admin approval page: $admin_link";
	global $post;
	$mb_business_email = get_post_meta($post->ID, 'mb_email', true);

        @wp_mail("{$mb_business_email}", "Your Website: New Review Posted on " . date('m/d/Y h:i'), "A new review has been posted for " . $this->options['business_name'] . " via WP Customer Reviews. nnYou will need to login to the admin area and approve this review before it will appear on your site.nn{$admin_link}");

These few tweaks enable more control over the output on the pages where you enable WPCR, keeping the features for products active as well. You can download the wp-customer-reviews.php file with the setup and above changes for reference or to replace the original with.

Updated wp-customer-reviews.php Download

This file will have the setup and implemented features, so all you would have to do is create custom fields according to the readme.txt file. You can change the custom field names in the wp-customer-reviews.php file by changing the lines mentioned in this tutorial.

[Download not found]

Feel free to suggest improvements, fixes or request features to include in this or upcoming tutorials. Upcoming articles will include tutorials that enable the recognizing of WordPress / BuddyPress members, avatars and links to BuddyPress profiles from member custom names.

I'm a developer at Maximus Business.
  • indra
    im still waiting for tutorials that enables the recognizing of WordPress / BuddyPress members to WP Customer Reviews, thanks in advance.

    Said on Sep 28, 2012 by indra - Reply
    • Profile photo of Maximilian
      Maximilian Rutheactive 1 week ago
      thanks for the note, will have those shortly.

      Said on Sep 28, 2012 by Maximilian Ruthe - Reply
  • Jo
    Thanks for the extra tutorial. Good references to consider. Just wondering though how it can go to a e.g. Thank You page (to be setup) once they submitted the review?

    Said on Oct 20, 2012 by Jo - Reply
  • Sharon
    Thanks for sharing this. Would love to learn how to display an average star rating on each page. ***** (five stars for you)

    Said on Nov 17, 2012 by Sharon - Reply
  • Derek
    Sounds great - where's the link to download the file? ... wp-customer-reviews.php

    Said on Jan 21, 2013 by Derek - Reply
  • Derek
    How can I customize the name of the sender I see in my email client? Right now it says "unknown sender"

    Said on Jan 21, 2013 by Derek - Reply
  • Profile photo of Todd
    Toddactive 1 year, 9 months ago
    I was excited to see some info on making this form avaialble only to logged in subscribers. The " if (is_user_logged_in())" before the output, did not have any effect on my site whatsoever? Any trouble shooting tips?

    Said on Feb 7, 2013 by Todd - Reply

Leave a Reply

Please feel free to give us your feedback and comment below. Please keep in mind that comments are moderated. Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>