Fix blank product page for WP e-Commerce and Thesis
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
(you may comment below while yawning)
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 }
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?
hi tim
sorry about that ” 31963bfunction temp_remove_filter(){ ” should be ” function temp_remove_filter(){ “
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
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
SUPERB !! Works a treat – thank you so much for providing this solution
Where is custom-functions.php? Can’t seem to find it?
you will find it in this folder …/wp-content/themes/thesis/custom
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?
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 productfor single product page. find code in comments below
You’re a legend mate!!! Well done
Been trawling through code for hours before I found this
tnx
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
hi Tman
this fix works only if you are using thesis as your theme
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.
you are welcome
actually am listed on e-lance
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.
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
let me check on that
I’m having this same issue. Any help would be greatly appreciated!
Thanks!
single product page fix is available in the comments below
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
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);
}
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!
yes just place it anywhere in custom_functions.php
this is located in thesis custom folder
THIS IS BRILJANT AND MADE MY DAY!
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
Nvm my additional question, apparently refreshing the permalinks fixes it
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
Hi Patrick
this has not been tested on Thesis 2.0,
You rock!
Thanks!
Does this coding work for thesis 2.1 also?
i have not tested it on thesis 2.x, it might work
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?
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
I got that error when trying to access product categories or variation
( Missing argument 3 for wpsc_variation_parent_dropdown_args() )
any help !