Skip to content

Instantly share code, notes, and snippets.

@orangerdev
Created January 2, 2019 07:41
Show Gist options
  • Save orangerdev/01ddd8af4f387543a51151b2483e4d8c to your computer and use it in GitHub Desktop.
Save orangerdev/01ddd8af4f387543a51151b2483e4d8c to your computer and use it in GitHub Desktop.
Function to override woocommerce template with your plugin templates
<?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