Skip to content

Instantly share code, notes, and snippets.

@asalkey
Created October 9, 2015 17:15
Show Gist options
  • Save asalkey/158fcdc9c95d27333918 to your computer and use it in GitHub Desktop.
Save asalkey/158fcdc9c95d27333918 to your computer and use it in GitHub Desktop.
Override WooCommerce templates in plugin
<?php
add_filter('wc_get_template','wholesaler_template'), 10, 5);
add_filter( 'wc_get_template_part', 'wholesaler_template_parts'), 10, 3);
public function wholesaler_template($located, $template_name, $args, $template_path, $default_path) {
global $woocommerce;
$newpath = plugin_dir_path( __FILE__ ) . '/woocommerce/' . $template_name;
return file_exists( $newpath ) ? $newpath : $located;
}
public function wholesaler_template_parts( $template, $slug, $name )
{
$plugin_path = plugin_dir_path( __FILE__ ) . '/woocommerce/';
if ( $name ) {
$newpath = $plugin_path . "{$slug}-{$name}.php";
} else {
$newpath = $plugin_path . "{$slug}.php";
}
return file_exists( $newpath ) ? $newpath : $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment