Fix blank product page for WP e-Commerce and Thesis

by admin on May 13, 2012

Quick Fix  please copy and past the code below, into custom_functions.php


if(function_exists('wpsc_enable_page_filters')){
function temp_remove_filter(){
remove_filter( 'the_content', 'wpsc_products_page', 1 );
}
add_action('wp_loaded','temp_remove_filter',1);

function return_filter(){
add_filter( 'the_content', 'wpsc_products_page', 1 );
}
add_action('thesis_hook_after_header','return_filter',10);
}

after pasting,  do the following 2 steps
step 1 take a big yawn

(you may comment below while yawning)

step 2 continue setting up your site

PS: if you are not a geek   DO NOT READ FURTHER.  have a nice day

The specifications  are:  Thesis version 1.8  and WP e-Commerce Version 3.8.8.

At this point, we shall go through some basics so as to get a clear understanding on this bug.

WP e-commerce (which is abbreviated WPEC), displays the product page and other pages using the_content filter.

All this action can be found in  ..\wp-content\plugins\wp-e-commerce\wpsc-includes\theme.functions.php on line 1248 or there about.

This  content  filter “add_filter( ‘the_content’, ‘wpsc_products_page’, 1 );” and many others  are added using a function called wpsc_enable_page_filters.

By observing the code you will notice that  the function hooked to the_content filter is  wpsc_products_page.  This is the function responsible for displaying the product page.

on scrutinizing this function you will come across the following logic

$wp_query->current_post = $wp_query->post_count;  (by the way we are still in the same file ” theme.functions.php “, on line 1028 or there about)

i can not claim to know why the above line of code is necessary  (actually i would greatly appreciate getting some insight on that) however i can ascertain that  this line of code  is the basis of our problem.

Analyzing the code from a thesis perspective, we can follow its  execution  up to a point,  where by thesis is building the page header.

The line of code that we are interested in can be found in …\wp-content\themes\thesis_18\lib\classes\head.php on line 12 or there about. On that line  you will find the following function call , $head->meta();. In this function we can jump up to line 146. On this line we find the following line $excerpt = trim(str_replace(‘[...]‘, ”, wp_trim_excerpt(”))); being executed.

in this line we will focus on the wp_trim_excerpt(”) function call. the code for this function is located in ..\wp-includes\formatting.php

In this function we are interested in line 2003. on this line, the execution calls $text = apply_filters(‘the_content’, $text);

At this point (kaboom),  Thesis and WPEC  collied.

By applying  “the_content” filter, essentially the code also executes wpsc_products_page which was hooked using “add_filter( ‘the_content’, ‘wpsc_products_page’, 1 ); ” at the wrong place and time. This is further aggravated by the fact that  ‘wpsc_products_page‘  function runs  $wp_query->current_post = $wp_query->post_count;  Note: this code sets  $wp_query->current_post and gives it a value of 1

As thesis continues to execute we reach a point where the content is rendered.  Lets take it from  thesis_loop::page(); the code is located in ..\wp-content\themes\thesis_18\lib\classes\loop.php.

On Line 27 we have while (have_posts()) { … .

looking at  the execution of  have_posts() on line 746 in  ..\wp-includes\query.php

we find that the code calls $wp_query->have_posts(), which takes as to line 2810 in the same file. On this line we have the following condition check if ( $this->current_post + 1 < $this->post_count ) {.

$this->current_post is already set to 1 by previous code execution.($wp_query->current_post = $wp_query->post_count;),  and  $this->post_count  will always be equal to 1.  So the condition above is similar to  if ( 1 + 1 < 1) {,  therefore the condition fails and the loop is not executed, this  results to  a blank page. :-(

moral of the story:   Quick Fix above simply removes the  ( ‘the_content’, ‘wpsc_products_page’)  filter and then adds it back after the creation of the page header. :-) .

 

Note: if you set the product page as the home page, the code execution follows a different path, therefore the   page is successfully displayed without the quick fix.

 

Cost: as a professional software developer i would have charged around $230 to sort out the above bug

{ 36 comments… read them below or add one }

Tim May 16, 2012 at 4:29 pm

Thanks for posting this. Having trouble with the blank page issue. When I pasted this into my custom functions, it took down my site. Seem there was some problem with two lines of code:

31963bfunction temp_remove_filter(){

and

add_action (‘thesis_hook_after_header’,’return_filter’,10);

any suggestions?

Reply

admin May 30, 2012 at 5:19 am

hi tim

sorry about that ” 31963bfunction temp_remove_filter(){ ” should be ” function temp_remove_filter(){

Reply

Chris May 30, 2012 at 7:59 pm

Thanks for taking the time to work this out, but I’m still having problems . . . I did the paste and the yawn, but upon hitting the save button it crashed the site with the following error :

Parse error: syntax error, unexpected T_STRING in /data04/c5280505/public_html/wp-content/themes/thesis_184/custom/custom_functions.php on line 11

I have completely cleared the custom_functions.php file so only your code is in it – line 11 is therefore :
add_action(‘thesis_hook_after_header’,’return_filter’,10);

Any suggestions ? (your help on this is appreciated :-)

Reply

admin June 1, 2012 at 1:14 pm

hi Chris

the problem is with the quotes used on the string variables, wordpress is distorting them.

i have worked on this and now you can safely copy and paste the code (use the view source button on the top right coner of the code).

tnx

Reply

Chris June 1, 2012 at 9:55 pm

SUPERB !! Works a treat – thank you so much for providing this solution :-)

Reply

Declan June 2, 2012 at 9:37 pm

Where is custom-functions.php? Can’t seem to find it?

Reply

admin June 2, 2012 at 11:47 pm

you will find it in this folder …/wp-content/themes/thesis/custom

Reply

mike June 2, 2012 at 11:20 pm

No luck with this. Pasted it into my custom functions.php and still just get a blank page with a title when on single product page. Any ideas?

Reply

admin June 2, 2012 at 11:51 pm

this is a fix for the Products Page (page where all products are listed), not the single product page.

for single product page go to settings and try saving your Permalinks again.

Also, try adding content to the single product

Reply

admin October 20, 2012 at 10:02 am

for single product page. find code in comments below

Reply

Bryan June 15, 2012 at 3:23 am

You’re a legend mate!!! Well done :)

Been trawling through code for hours before I found this :)

Reply

admin June 15, 2012 at 1:45 pm

tnx

Reply

Tman June 15, 2012 at 2:33 pm

Thanx for the info and time. I wrapped my head around the concept and tried to use this with WPEC and my briefcase theme. Oddly enough i could not find a custom_functions.php in my files, The Theme uses Their ormx style controlling. Did i miss something or any ideas . Thanx

Reply

admin June 15, 2012 at 6:44 pm

hi Tman
this fix works only if you are using thesis as your theme

Reply

Jenny August 8, 2012 at 8:09 pm

Thank you thank you thank you!! You have just saved me spending money on e-lance! I have been tearing my hair out for hours trying to sort out the ‘blank page’ mystery. I don’t know how the hell you put that code together but I’m glad you do. Thanks for making it so much easier for us non-coder folk. Cheers. ;-)

Reply

admin August 10, 2012 at 6:55 pm

you are welcome
actually am listed on e-lance

Reply

coderXO August 13, 2012 at 3:30 pm

Thanks for the tip. It helped. I write WP plugins but know little to nothing about themes. Saved me the time digging into Thesis.

Cheers.

Reply

smoke-e-joe September 18, 2012 at 1:41 am

On the single products page its not displaying variations or any of the form data But is showing content like a Normal post. Will this script work if that page is referenced instead as i think its the same problem. Thanks

Reply

admin September 19, 2012 at 3:59 pm

let me check on that

Reply

Nina September 24, 2012 at 8:04 pm

I’m having this same issue. Any help would be greatly appreciated!

Thanks!

Reply

admin October 20, 2012 at 10:16 am

single product page fix is available in the comments below

Reply

joe mallen September 19, 2012 at 10:36 pm

Thought id share this as i figured it out. The single product page wasn’t displaying properly no variations add to cart button etc. Pretty simple really as it uses the same function i just had to look in the theme.functions.php file to find the function for the single product page on line 392 called wpsc_single_template.

Anyway here’ the code if anyone else needs it. Im sure the 2 functions could be condensed in to one but it works.

if(function_exists('wpsc_enable_page_filters')){
function temp_remove_filter2(){
remove_filter( 'the_content', 'wpsc_single_template', 1 );
}
add_action('wp_loaded','temp_remove_filter2',1);

function return_filter2(){
add_filter( 'the_content', 'wpsc_single_template', 1 );
}
add_action('thesis_hook_after_header','return_filter2',10);
}

Cheers

Reply

admin October 13, 2012 at 7:29 am

nice catch Thanks

Here is the combined version

if(function_exists('wpsc_enable_page_filters')){
function temp_remove_filter(){
remove_filter( 'the_content', 'wpsc_products_page', 1 );
remove_filter( 'the_content', 'wpsc_single_template', 1 );
}
add_action('wp_loaded','temp_remove_filter',1);

function return_filter(){
add_filter( 'the_content', 'wpsc_products_page', 1 );
add_filter( 'the_content', 'wpsc_single_template', 1 );
}
add_action('thesis_hook_after_header','return_filter',10);
}

Reply

Laura October 14, 2012 at 1:17 am

This looks like exactly what I need. Do I just put that code into my single_template file in a random place? I want to implement it I just don’t know much about the fancy coding stuff.

Thanks so much!

Reply

admin October 20, 2012 at 8:37 am

yes just place it anywhere in custom_functions.php
this is located in thesis custom folder

Reply

marre October 23, 2012 at 3:37 pm

THIS IS BRILJANT AND MADE MY DAY!

Reply

Mike Montgomery November 2, 2012 at 7:10 am

You freaking rock! This was the reason I wasn’t bothering using wp-ecommerce on my sites, thank you so much for posting the fix! I do have a question though and I’m not sure if it’s because of this code or perhaps a category issue on my site, when I click on the product name it takes me to the ‘you 404′d it dude’ page. You can see it here if you click on the string: http://www.yoyocourse.com/store If you know what I did wrong and can help I appreciate it, if not, thanks for getting me closer than I was before :)

Reply

Mike Montgomery November 2, 2012 at 7:12 am

Nvm my additional question, apparently refreshing the permalinks fixes it :)

Reply

Patrick Willmott April 29, 2013 at 11:57 am

Hi,

Can anyone tell me it this fix work for Thesis 2.0?

Or if anyone is running on 2.0 and has another fix.

Your help is greatly appreciated!

Patrick

Reply

admin April 30, 2013 at 11:03 am

Hi Patrick

this has not been tested on Thesis 2.0,

Reply

robert September 26, 2013 at 1:05 pm

You rock!

Thanks!

Reply

Robin October 20, 2013 at 1:53 am

Does this coding work for thesis 2.1 also?

Reply

admin October 20, 2013 at 2:59 pm

i have not tested it on thesis 2.x, it might work

Reply

Lauren December 6, 2013 at 1:28 pm

I am having the same blank product page problem but use a Storefront theme, not Thesis. I’ve spent hours looking for a solution and this is the only thing I’ve found – will the code work on another theme?

Reply

admin December 8, 2013 at 11:13 am

this particular code is only tested using thesis. it might work in another theme if the coding logic is similar to that of thesis.
i.e calling apply_filters(‘the_content’, $text); in the header.

try remove_filter( ‘the_content’, ‘wpsc_products_page’, 1 ); – See more at: http://assortmentofsites.com/fix-blank-product-page-for-wp-e-commerce-and-thesis/#sthash.Fp2Kz7JO.dpuf before the theme starts creating the page.
and then return the filter using various wordpress hooks until you find the hook that works for you

Reply

dyana March 16, 2016 at 12:26 pm

I got that error when trying to access product categories or variation
( Missing argument 3 for wpsc_variation_parent_dropdown_args() )
any help !

Reply

Cancel reply

Leave a Comment