Skip to content

Instantly share code, notes, and snippets.

@Dilden
Created September 28, 2016 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Dilden/9434913e456fcb1cdb141685d9fb671f to your computer and use it in GitHub Desktop.
Save Dilden/9434913e456fcb1cdb141685d9fb671f to your computer and use it in GitHub Desktop.
Useful snippet for overriding WooCommerce templates in your custom WordPress plugin. Just follow the same directory structure as if you were overriding the templates from a theme.
// Override woocommerce templates with the templates in my plugin
add_filter( 'woocommerce_locate_template', 'custom_plugin_templates');
function custom_plugin_templates ( $template, $template_name, $template_path ) {
$check_dis = str_replace('woocommerce', 'your-plugin-name-goes-here/woocommerce', $template);
if(file_exists($check_dis)) {
$template = $check_dis;
}
return $template;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment