This video is part of our old WP eStore Course Go to our Updated WP eStore Course for current videos.
Using Comments as Product Reviews
Welcome to Lesson 16 of the Build Your Own E-Commerce Website tutorial series. The goal of this tutorial series has been to show you how to create a fully functional e-commerce website using WordPress, Thesis and WP eStore. In this final lesson we’ll learn how to use the WordPress Comment System for providing product reviews.
Understanding Thesis Filters
We’ll start off by looking at the elements of the site that we’ll need to change and then we’ll introduce Thesis Filters. Next we’ll use Thesis Filters to transform the comments labels into product review labels. Then we’ll use the WordPress template tag to change some of the additional comment labels, and then finally we’ll use Recent Comments widget to display our product reviews.
Identify Elements that Need to Change
First we’re going to look at the elements we need to change and then get an introduction to the Thesis Filters. In order for us to see what we need to change let’s go to my demonstration site which is www.thesisestore.com, this top link here. In this demonstration site we have an example of a Recent Reviews widget and then if you look at our products you can see that down here it says Write a Review of This Product. For those where we do have reviews, for example the Apple Ardor E-Book, scroll down here you can see that it says, 2 Customer Reviews, Add Your Own Review.
So these are the two sections that we are changing. We are changing the form title and the introductory text. The way we’re going to do that is by using Thesis Filter Hooks.
An Introduction to Thesis Filter Hooks
What I’d like you to do is go to the DIY Themes User Guide. There is a link to that here but we’ll just go ahead and log in, www.diythemes.com and we’ll select the User Guide and then I want to take a look at the Customize Thesis with Filters.
Okay so what is a filter? According to the User Guide a filter, similar to a hook, is a point of interaction with Thesis and just like hooks you need to create an Add Functions to filters to achieve the results. The difference between a Thesis filter and a hook is that a filter has to operate on content that already exists. So this isn’t going to add something new to the page, this is going to modify content that already exists on a page. Another way of saying that is that a filter is a location where there is a default output but allows that output to be modified or replaced.
Review the Filter Hooks Example in the User Guide
For example, the User Guide uses a comments example similar to what we’ll be doing. This is the default output of that introductory text. It uses the thesis_comments_intro filter and you can replace all of this contents or part of these contents by using that filter. In this case what they are doing is grabbing this little section of the contents, that is the phrase, add one and they are going to replace with shout at me.
The way they do that is create a function and specify what the return of that function is going to be. In this case they’ve given it a variable name, content and then rather than replacing all of the content what they are going to do is they are just going to replace this one little section of the content. Since they’re just replacing that section of the content they are using a PHP function called string replace and this string replace function will replace this text string, add one with another text string, Shout @ me and it will do that on the block of text that’s in the variable content.
Since content is what’s being returned here this will actually act on the entire section of the filter and so what’s going to happen is it’s going to take 21 Comments … read them below or add one and of that section of the filter it is going to replace this one string element. So you have the string, you have it returning the content and then finally what you have is the hook, or in this case the filter that it gets added to.
So the syntax here is instead of add action, it’s add filter and then the name of the filter that you are going to affect which in this case is thesis_comments_intro and then the name of the function that you are using to effect that which in this case is custom_comment_intro. This is what the net result of that is. Now it says 21 Comments … read them below or Shout @ Me.
So that wraps up Part 1 of Lesson 16 of the Build Your Own E-Commerce Website tutorial series.