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 #10 from mejta/master
Browse files Browse the repository at this point in the history
wc_get_template enhancements
  • Loading branch information
mmirus authored Aug 23, 2018
2 parents 9be3fff + 042c544 commit 71564eb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
16 changes: 16 additions & 0 deletions examples/resources/views/woocommerce/archive-product.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{{--
The Template for displaying product archives, including the main shop page which is a post type archive
This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
HOWEVER, on occasion WooCommerce will need to update template files and you
(the theme developer) will need to copy the new files to your theme to
maintain compatibility. We try to do this as little as possible, but it does
happen. When this occurs the version of the template file will be bumped and
the readme will list any important changes.
@see https://docs.woocommerce.com/document/template-structure/
@package WooCommerce/Templates
@version 3.4.0
--}}

@extends('layouts.app')

@section('content')
Expand Down
17 changes: 17 additions & 0 deletions examples/resources/views/woocommerce/single-product.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
{{--
The Template for displaying all single products
This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
HOWEVER, on occasion WooCommerce will need to update template files and you
(the theme developer) will need to copy the new files to your theme to
maintain compatibility. We try to do this as little as possible, but it does
happen. When this occurs the version of the template file will be bumped and
the readme will list any important changes.
@see https://docs.woocommerce.com/document/template-structure/
@author WooThemes
@package WooCommerce/Templates
@version 1.6.4
--}}

@extends('layouts.app')

@section('content')
Expand Down
40 changes: 30 additions & 10 deletions src/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,49 @@
add_filter('template_include', function ($template) {
return strpos($template, WC_ABSPATH) === -1
? $template
: locate_template('woocommerce/' . 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) {
$theme_template = locate_template('woocommerce/' . str_replace(WC_ABSPATH . 'templates/', '', $template));
$theme_template = locate_template(WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template));

if ($theme_template) {
echo template($theme_template);
$data = collect(get_body_class())->reduce(function ($data, $class) {
return apply_filters("sage/template/{$class}/data", $data);
}, []);

echo template($theme_template, $data);
return get_stylesheet_directory() . '/index.php';
}

return $template;
}, PHP_INT_MAX, 1);

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) {
$data = collect(get_body_class())->reduce(function ($data, $class) {
return apply_filters("sage/template/{$class}/data", $data);
}, []);

echo template($theme_template, array_merge(
compact(explode(' ', 'template_name template_path located args')),
$data,
$args
));
}
}, PHP_INT_MAX, 4);

add_filter('wc_get_template', function ($template, $template_name, $args) {
$theme_template = locate_template('woocommerce/' . $template_name);
$theme_template = locate_template(WC()->template_path() . $template_name);

// Don't render template when used in REST
if ($theme_template && !(defined('REST_REQUEST') && REST_REQUEST)) {
echo template($theme_template, $args);
return get_stylesheet_directory() . '/index.php';
// 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_path($theme_template, $args) : $template;
}, PHP_INT_MAX, 3);
// return empty file, output already rendered by 'woocommerce_before_template_part' hook
return $theme_template ? get_stylesheet_directory() . '/index.php' : $template;
}, 100, 3);
}

0 comments on commit 71564eb

Please sign in to comment.