WooCommerce Template Override Issue.

November 1, 2016 9:16 pm

Hello again!

Just wanted to start a discussion for an Issue I had where a custom theme template I was creating was not being overwritten within the WooCommerce store. I found that this due to the GoToWP plugin having the woocommerce dir and templates in the plugin dir.

By default, WooCommerce looks at the following directories in this order for templates.
/your theme/tempalte
/your theme/woocomerce/tempalte
/your plugin/woocommerce/tempalte
/default path/tempalte

Because of this, it is possible to lose the ability to overwrite tempaltes in your theme because of a plugin. Most of the time this can be handled via actions or filters but there are some instances where a complete override is needed.

I have 2 suggestions to solve this.

1. Is to create a function within the GoToWP plugin to allow for theme template overrides to take priority followed by the plugin defaults and then the woocommerce defaults. You’d also need to provide documentation to add the plugin template mods into the custom theme templates. This can be achieved with the following code:

function myplugin_plugin_path() {

// gets the absolute path to this plugin directory

return untrailingslashit( plugin_dir_path( __FILE__ ) );


add_filter( ‘woocommerce_locate_template’, ‘myplugin_woocommerce_locate_template’, 10, 3 );

function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {

global $woocommerce;

$_template = $template;

if ( ! $template_path ) $template_path = $woocommerce->template_url;

$plugin_path = myplugin_plugin_path() . ‘/woocommerce/’;

// Look within passed path within the theme – this is priority

$template = locate_template(


$template_path . $template_name,




// Modification: Get the template from this plugin, if it exists

if ( ! $template && file_exists( $plugin_path . $template_name ) )

$template = $plugin_path . $template_name;

// Use default template

if ( ! $template )

$template = $_template;

// Return what we found

return $template;


2. This option would require GoToWP to remove their WooCommerce templates and only use filters or actions to override output where applicable. This option will take quite a bit more work and might not even be possible after looking that the modifications made to those templates in the plugin.

I was able to solve this temporarily with the first solution by adding that code to my theme and called the plugin_dir_path() with the GOTOWP_PREMIUM_PLUGIN_PATH constant.

Looking forward to your response.

Published by 1 Comment

1 Reply

Leave a Reply

Your email address will not be published.