Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from roots/reviews-template
Browse files Browse the repository at this point in the history
Enable overriding `single-product-reviews` template
  • Loading branch information
mmirus authored Aug 27, 2018
2 parents 71564eb + 65bc347 commit acd3233
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
: locate_template(WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template)) ? : $template;
}
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));
Expand All @@ -27,7 +34,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) {
Expand All @@ -48,7 +55,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
Expand Down

0 comments on commit acd3233

Please sign in to comment.