WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to write a plugin for WooCommerce (https://github.com/bassjobsen/woocommerce-twitterbootstrap). I want my templates load like this:

  1. my custom theme / template path / template name
  2. my custom theme / template
  3. my plugin / template name
  4. woocommerce / template name

So when the template not exists in the theme folder it is load from my plugin folder (if exists) instead of the Woocommece folder. On http://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/ if found a working solution for templates load by woocommerce_get_template. But this will not work for woocommerce_get_template_part cause this function call locate_template instead of woocommerce_locate_template (is this a bug?).

Question: I want to know how to overwrite / manipulate locate_template() so it try to load the files from my plugin folder first. Or any other solution to do this.

update thanks to @jesper i cloud load templates now:


   //pages you want to make true, ex. is_shop()
   global $woocommerce;
   if(is_shop()) {

       $plugin_dir = WP_PLUGIN_DIR.'/'.str_replace( basename( __FILE__), "", plugin_basename(__FILE__) );


    load_template($plugin_dir . '/templates/archive-product.php');


/templates/archive-product.php includes content-product.php from the same plugin template dir. content-product.php makes use of the global $product which is null in this case. Do i need to load a other function to set $product?

The above also gives my an other error: PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'woocommerce_before_main_content_grid' not found or invalid function name in /home/bass/Dropbox/testomgeving/jamedotheme/wordpress/wp-includes/plugin.php

With the above code i could write a function to conditional include files in templates/archive-product.php (so solved!)

share|improve this question
At this time locate_template has no filter nor action hooks and is not a pluggable function: you cannot overwrite / manipulate it without change the core file wp-includes/template.php. – gmazzap Aug 19 '13 at 2:10
up vote 1 down vote accepted

I think you can use template redirect action.

I don't test it but it should work:

function my_template_redirect(){
   //pages you want to make true, ex. is_shop()
   if(is_shop()) {
       $plugin_dir = WP_PLUGIN_DIR.'/'.str_replace( basename( __FILE__), "", plugin_basename(__FILE__) );
    load_template($plugin_dir . 'your-template.php');

share|improve this answer
thanks. This does not seems to set $name. $name will be always empty. – Bass Jobsen Aug 19 '13 at 7:18
I copied from a plugin I coded, check it now, change de variable to the name of your template. – jepser Aug 19 '13 at 17:50
Thanks. It will work some way. If will have to check if i need some conditional use of this action. Now i found the template twice (one on the right place and one on the end of the source). – Bass Jobsen Aug 19 '13 at 18:36
hi @jesper thanks. Yes i can load templates now, but the product var needed for the loop is not set, see update of my question – Bass Jobsen Aug 19 '13 at 22:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.