From f135efbd1687b4d8c1e276ca9ade0aa771f76ab9 Mon Sep 17 00:00:00 2001 From: Matt Mirus Date: Mon, 27 Aug 2018 15:02:58 -0400 Subject: [PATCH 1/2] Use PSR-2 --- src/woocommerce.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/woocommerce.php b/src/woocommerce.php index db53165..fefa9df 100644 --- a/src/woocommerce.php +++ b/src/woocommerce.php @@ -9,7 +9,7 @@ add_filter('template_include', function ($template) { return strpos($template, WC_ABSPATH) === -1 ? $template - : locate_template(WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template)) ?: $template; + : locate_template(WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template)) ? : $template; }, 100, 1); add_filter('wc_get_template_part', function ($template) { @@ -27,7 +27,7 @@ return $template; }, PHP_INT_MAX, 1); - add_action('woocommerce_before_template_part', function($template_name, $template_path, $located, $args) { + add_action('woocommerce_before_template_part', function ($template_name, $template_path, $located, $args) { $theme_template = locate_template(WC()->template_path() . $template_name); if ($theme_template) { @@ -48,7 +48,7 @@ // return theme filename for status screen if (is_admin() && function_exists('get_current_screen') && get_current_screen()->id === 'woocommerce_page_wc-status') { - return $theme_template ?: $template; + return $theme_template ? : $template; } // return empty file, output already rendered by 'woocommerce_before_template_part' hook From 65bc347098055a545531039a26b0b07b80fd380b Mon Sep 17 00:00:00 2001 From: Matt Mirus Date: Mon, 27 Aug 2018 15:04:36 -0400 Subject: [PATCH 2/2] Enable overriding --- src/woocommerce.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/woocommerce.php b/src/woocommerce.php index fefa9df..305178c 100644 --- a/src/woocommerce.php +++ b/src/woocommerce.php @@ -6,11 +6,18 @@ add_theme_support('woocommerce'); }); - add_filter('template_include', function ($template) { + /** + * @param string $template + * @return string + */ + function wc_template_loader(String $template) + { return strpos($template, WC_ABSPATH) === -1 ? $template : locate_template(WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template)) ? : $template; - }, 100, 1); + } + add_filter('template_include', __NAMESPACE__ . '\\wc_template_loader', 100, 1); + add_filter('comments_template', __NAMESPACE__ . '\\wc_template_loader', 100, 1); add_filter('wc_get_template_part', function ($template) { $theme_template = locate_template(WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template));