Skip to content

Instantly share code, notes, and snippets.

@BKeanu1989
Created April 5, 2018 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BKeanu1989/03580186de7fcaeaac56a289ead11f07 to your computer and use it in GitHub Desktop.
Save BKeanu1989/03580186de7fcaeaac56a289ead11f07 to your computer and use it in GitHub Desktop.
overwrite woocommerce template in plugin --- source: https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/
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(
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment