forked from roots/sage-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for Stage & Sage 10 support
- Loading branch information
Showing
5 changed files
with
137 additions
and
93 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"name": "roots/sage-woocommerce", | ||
"description": "WooCommerce integration for Sage 9", | ||
"name": "ouun/stage-woocommerce", | ||
"description": "WooCommerce integration for Stage & Sage 10", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Daniel Mejta", | ||
"email": "[email protected]" | ||
"name": "Philipp", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,140 @@ | ||
<?php | ||
namespace App; | ||
namespace Roots; | ||
|
||
if (defined('WC_ABSPATH')) { | ||
|
||
/** | ||
* Set WooCommerce Theme Support | ||
*/ | ||
add_action('after_setup_theme', function () { | ||
add_theme_support('woocommerce'); | ||
}); | ||
|
||
add_filter('template_include', function ($template) { | ||
return strpos($template, WC_ABSPATH) === -1 | ||
? $template | ||
: locate_template('woocommerce/' . 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)); | ||
return $theme_template ? template_path($theme_template) : $template; | ||
}, 100, 1); | ||
|
||
add_filter('wc_get_template', function ($template, $template_name, $args) { | ||
$theme_template = locate_template('woocommerce/' . $template_name); | ||
return $theme_template ? template_path($theme_template, $args) : $template; | ||
}, 100, 3); | ||
/** | ||
* Set template path to /shop | ||
*/ | ||
add_filter( | ||
'woocommerce_template_path', | ||
function () { | ||
return 'shop/'; | ||
}, | ||
100, | ||
1 | ||
); | ||
|
||
/** | ||
* @param string $template | ||
* | ||
* @return string | ||
*/ | ||
function wc_template_loader(string $template) | ||
{ | ||
|
||
if (strpos($template, WC_ABSPATH) === - 1) { | ||
return $template; | ||
} | ||
|
||
return locate_template( | ||
app('sage.finder')->locate( | ||
WC()->template_path() . str_replace( | ||
WC_ABSPATH . 'templates/', | ||
'', | ||
$template | ||
) | ||
) | ||
) ?: $template; | ||
} | ||
|
||
add_filter('template_include', __NAMESPACE__ . '\\wc_template_loader', 90, 1); | ||
add_filter('comments_template', __NAMESPACE__ . '\\wc_template_loader', 100, 1); | ||
|
||
add_filter( | ||
'wc_get_template_part', | ||
function ($template) { | ||
$theme_template = locate_template( | ||
app('sage.finder')->locate( | ||
WC()->template_path() . str_replace(WC_ABSPATH . 'templates/', '', $template) | ||
) | ||
); | ||
|
||
if ($theme_template) { | ||
$view = app('view.finder') | ||
->getPossibleViewNameFromPath($file = realpath($theme_template)); | ||
|
||
$view = trim($view, '\\/.'); | ||
|
||
/** Gather data to be passed to view */ | ||
$data = array_reduce( | ||
get_body_class(), | ||
function ($data, $class) use ($view, $file) { | ||
return apply_filters("sage/template/{$class}/data", $data, $view, $file); | ||
}, | ||
array() | ||
); | ||
|
||
echo view($view, $data)->render(); | ||
} | ||
|
||
return $template; | ||
}, | ||
PHP_INT_MAX, | ||
1 | ||
); | ||
|
||
add_action( | ||
'woocommerce_before_template_part', | ||
function ($template_name, $template_path, $located, $args) { | ||
$theme_template = locate_template(app('sage.finder')->locate(WC()->template_path() . $template_name)); | ||
|
||
if ($theme_template) { | ||
$view = app('view.finder') | ||
->getPossibleViewNameFromPath($file = realpath($theme_template)); | ||
|
||
$view = trim($view, '\\/.'); | ||
|
||
/** Gather data to be passed to view */ | ||
$data = array_reduce( | ||
get_body_class(), | ||
function ($data, $class) use ($view, $file) { | ||
return apply_filters("sage/template/{$class}/data", $data, $view, $file); | ||
}, | ||
array() | ||
); | ||
|
||
echo view( | ||
$view, | ||
array_merge( | ||
compact(explode(' ', 'template_name template_path located args')), | ||
$data, | ||
$args | ||
) | ||
)->render(); | ||
} | ||
}, | ||
PHP_INT_MAX, | ||
4 | ||
); | ||
|
||
add_filter( | ||
'wc_get_template', | ||
function ($template, $template_name, $args) { | ||
$theme_template = locate_template(app('sage.finder')->locate(WC()->template_path() . $template_name)); | ||
|
||
// return theme filename for status screen | ||
if ( | ||
is_admin() && | ||
! wp_doing_ajax() && | ||
function_exists('get_current_screen') && | ||
get_current_screen() && | ||
get_current_screen()->id === 'woocommerce_page_wc-status' | ||
) { | ||
return $theme_template ?: $template; | ||
} | ||
|
||
// return empty file, output already rendered by 'woocommerce_before_template_part' hook | ||
return $theme_template ? view('empty')->getPath() : $template; | ||
}, | ||
100, | ||
3 | ||
); | ||
} |