The Woocommerce plugin for views is causing a weird problem for me. I set the value of the Product template, and it works for a bit, then it stops working, or only works sporadically.
I think I've discovered why.
We run our sites on Pantheon, which has a load-balanced setup. That means the full path to WordPress resources can change as the bindings change.
In other words, /srv/bindings/1234/code/wp-content/plugins/woocommerce-views/templates/single-product.php
might become /srv/bindings/5678/code/wp-content/plugins/woocommerce-views/templates/single-product.php
So what happens is you set the value in the admin page for Woocommerce views, then another server serves the page, sees that the page doesn't exist on that server and bumps it back to default, which of course breaks your custom product page.
Link to a page where the issue can be seen:
hidden link
My temporary fix is to actually replace the single-product.php template in the Woocommerce plugin folder with the one from Woocommerce views (because even a copy in the child theme won't work), but this is obviously fraught with peril.
Hello,
This is an exception with your load-balanced web server.
In my opinion, the best option is synchronizing your website files and path in each servers , then Woocommerce Views plugin will be able to locate the same file in different web server.
And Woocommerce Views plugin is using a wordpress option "woocommerce_views_theme_template_file" to store the file path, and use wordpress function get_option() to retrieve the option value, so you can use filter hook "option_woocommerce_views_theme_template_file" to change the file path to what you want, for example:
add_filter('option_woocommerce_views_theme_template_file', function($value, $option){
return array('twentyseventeen' => '\www\wordpress\wp-content\plugins\woocommerce-views\templates\single-product-2.php');
}, 10, 2);
Please replace "twentyseventeen" with your theme slug
I assume there's no way to use a relative path to the WordPress installation directory?
Yes, it is possible, I have tried it in my localhost, you can use var ABSPATH to get the WordPress installation directory, then setup the template file path, for example:
add_filter('option_woocommerce_views_theme_template_file', function($value, $option){
return array('twentyseventeen' => ABSPATH . '\wp-content\plugins\woocommerce-views\templates\single-product.php');
}, 10, 2);
Hi,
I have the exact same problem and i tried your solution Luo but it didn't work.
I changed the theme slug and everything.
Any suggestions?