I need to override all of child theme templates woocommerce and parent templates in a plugin. Basically, I’m making couple of copies to my site that has some custom functionalities added via the child theme. So, in order to update all of the sites at once I want to use a plugin instead of a child theme. Because I assume it’s pretty difficult to make child theme do automatically updates. (maybe I’m wrong in this)
I’m using a parent theme that has different versions of woocommerce templates. For example, child-theme/woocommerce/cart/cart-v2.php is a cart template.
This is what I use to override woocommerce templates, but they override woocommerce plugin templates not parent theme templates.
add_filter( 'woocommerce_locate_template', 'woo_adon_plugin_template', 1, 3 );
function woo_adon_plugin_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path )
$template_path = $woocommerce->template_url;
$plugin_path = RCW2P_PLUGIN_PATH . '/templates/woocommerce/';
if(file_exists( $plugin_path . $template_name ))
$template = $plugin_path . $template_name;
if( ! $template )
$template = locate_template(
array(
$template_path . $template_name,
$template_name
)
);
if( ! $template && file_exists( $plugin_path . $template_name ) )
$template = $plugin_path . $template_name;
if ( ! $template )
$template = $_template;
return $template;
}
With this code I have to have this path for cart page plugin/templates/woocommerce/cart/cart.php
Also, this code doesn’t overrides templates files that are in woocommerce folder, such as taxonomy-product-cat.php
Any help is much appreciated.