Created
October 9, 2015 17:15
-
-
Save asalkey/158fcdc9c95d27333918 to your computer and use it in GitHub Desktop.
Override WooCommerce templates in plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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