This video is part of our old WP eStore Course Go to our Updated WP eStore Course for current videos.
Welcome back to Part 3 of Lesson 16 of the Build Your Own E-Commerce Website tutorial series. In this part of the lesson we are going to change the Comment Intro text into a Product Review using a Thesis filter.
Identify the Element to Change
The comments_intro text exists in places where there are comments. If we go to Products, Books and look at Apple Ardor – Confessions of a WordPress Trainer and we scroll down here you can see that I have written a couple of product reviews. It’s this section right here that we are going to change. We no longer want it to say 2 Comments – “Read them below or Add one”, we want it to say something else.
Let’s take a look at this filter. Come back over here to DIY Themes and look at Thesis Filters. This time the Thesis filter hook we are changing is thesis_comments_intro and you can see they give an example here but as you probably recall the thesis_comments_intro was the example that they used in the introduction to this. So let’s go back over to that and we’re going to use this code for making the change. Copy that block of code and then go back over, we’re going to come to our custom_functions.php file and paste that function under this little piece of comment text.
This isn’t really the function we want to use though obviously. We don’t want to replace “Add one” with “Shout @ Me”. What we really want to do is to replace Comments with Product Reviews.
String Replace Function
Before we get too far down the road on this let’s take a look at this string replace function. Open up a browser window and let’s search for string replace php. So that brings us to the PHP manual and this is the function, string replace. This function returns a string or an array with all occurrences of search, that’s the first one, in the subject replaced by the given replace value.
If we scroll down here and take a look at their example, it is in the string bodytag, replace body with black and then this is the string bodytag, bodytag equals body. So in our case what we are doing is we are doing a string replace for Comments, we are replacing it for Product Reviews. Instead of specifying explicitly what that text is going to be what we are doing is referring to a variable which is the filter.
Replace Comments with Product Reviews Using Thesis Filter Variable
Look at that filter variable – here is our variable which is the filter. So we are taking this block of text within the filter in Thesis that we are calling Content and we are finding every instance of Comments and we are replacing it with Product Reviews.
Let’s save that, upload it and then let’s test it. Now if we go to the Apple Ardor Book, and scroll down here, you can see that it must be comments with a small c. So let’s go back and change that. Instead of that let’s make it comments, save the document, upload the document, refresh the page and now you can see it says 2 Product Reviews … “Read them below or Add one”.
Make the Thesis Function Conditional for Product Posts Only
Unfortunately what’s happening here though is that the same thing happens when we look at a regular post. It says 2 Product Reviews … “Read them below or Add one”. We don’t want it to do that, we want this to be left alone so that means we have to use our conditional tag again. So here’s our if(in_category, 5 and 6) – let’s go ahead and copy that and we’ll place that above this. if(in_category, 5 or 6), then we want the content to have this string replace function otherwise we’re just going to go ahead and return the default content which in this case would be the 2 Comments … go ahead and add one situation.
Save this, let’s upload it again, let’s take a look at it here and now you can see that it says 2 comments…“Read them below or Add one” in the place where we have comments. If we look at a blog post without those– well let’s look at one with a comment. You can see here that it says 1 comment…”Read them below or Add one” and if we look at a blog post without any such as this one, it just says “Leave a comment”.
Now let’s take a look at how that affects our Books, or Our Products. This one says 2 Product Reviews…”Read them below or Add one”, but if we come over and take a look at a product that has only one product review — Lemon Zest and we scroll down here you can see that it didn’t say any, so it says 1 comment rather than 1 Product Review. So this is something that we’re going to have to address in the next part of this lesson.