Template structure & Overriding templates via a Plugin

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our Support Policy.

WooCommerce template files contain the markup and template structure for frontend and HTML emails of your store.

define( 'EYE__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );

add_filter( 'woocommerce_locate_template', 'plugin_woocommerce_locate_template', 10, 3 );

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

global $woocommerce;

$_template = $template;

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

$plugin_path = EYE__PLUGIN_DIR . '/woocommerce/';

// Look within passed path within the theme - this is priority
$template = locate_template(
array(
$template_path . $template_name,
$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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>