Created
January 2, 2019 07:41
-
-
Save orangerdev/01ddd8af4f387543a51151b2483e4d8c to your computer and use it in GitHub Desktop.
Function to override woocommerce template with your plugin templates
This file contains 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 | |
/** | |
* Return with custom template path | |
* Hooked via filter wc_get_template, priority 100 | |
* @param string $located [description] | |
* @param string $template_name [description] | |
* @param string $args [description] | |
* @param string $template_path [description] | |
* @param string $default_path [description] | |
* @return string [description] | |
*/ | |
function override_template($located, $template_name = '',$args = array(),$template_path = '',$default_path = '') | |
{ | |
$template_name = str_replace("myaccount","my-account",$template_name); | |
$file = YOU_PLUGIN_DIR . 'woocommerce' . '/' .$template_name; | |
$located = (file_exists($file)) ? $file : $located; | |
return $located; | |
} | |
// Filter to override the woocommerce template | |
add_filter('wc_get_template','override_template',999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment