Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rabinkumarpal/05cdd2ae08e3930065a5d5d45bdbe3a0 to your computer and use it in GitHub Desktop.
Save rabinkumarpal/05cdd2ae08e3930065a5d5d45bdbe3a0 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