How to use Woocommerce (3.4.3) with Sage 9.0.1 (Blade + SoberWP controllers), WP 4.9.7 (17/07/2018)
How to use Woocommerce (3.4.3) with Sage 9.0.1 (Blade + SoberWP controllers), WP 4.9.7 (17/07/2018)
Check dev branches for latest updates.
Check previous release if error with latest.
/plugins/woocommerce/templates/content-single-product.php
=> /your-sage-theme/resources/views/woocommerce/content-single-product.blade.php
/plugins/woocommerce/templates/single-product/meta.php
=> /your-sage-theme/resources/views/woocommerce/single-product/meta.blade.php
meta.blade.php
single-product
controller for single-product.blade.php
then content-single-product.blade.php
template)woocommerce.blade.php
. Had to force the template path into the Woocommerce default template array. See woocommerce_template_loader_files
filter code comment in filters.php
Editing shop page
/resources/views/woocommerce.blade.php
as first in woocommerce default template file array (see changelog)template_include
: edit single-product.php
and archive-product.php
template path to /resources/views/woocommerce/*.blade.php
(then retrieve controller data and render blade as usual)wc_get_template_part
: edit woocommerce template method to look for blade files then php fileswc_get_template
: tell woocommerce to get template from resources/views/
single-product.php
and archive-product.php
includes woocommerce.blade.php
templatewoocommerce.blade.php
calls our overrided App\woocommerce_content(get_defined_vars())
that output Woocommerce contentController.php
(new Loader()
) will parse all controller and methods and store them using "slugified" $template
name as keys in $this->instance
(the controller::class
object is stored)controller.php loader()
will add_filter('sage/template/' . $template . '-data/data')
for all controllers (filter string/controller) with a method that return, (among other datas) the controller data we wantsingle-product.php
template (changed as single-product.blade.php
in our add_filter('template_include')
and add_filter('wc_get_template_part')
updates targeted in /resources/views
thanks to our add_filter('wc_get_template')
) as template hierarchy rulesapply_filter('sage/template/' . $template . '-data/data')
(it uses body_class()
to find the $template
name to match the correct controllers with current template) to add data to the blade->render
(that also render sub-templates that could also need controller data) from template_include
filter (that we override but just for the "single-product.php" and "archive-product.php" replace update, and load controller data)resources/views/woocommerce/single-product.blade.php
), data are defined in get_defined_data()
(as rendered from filter template_include
with controllers data), so WE HAVE THE DATA HEREhelpers::template()
(We don't have HTMl here, we call a method to output Woocommerce content) using woocommerce
as template, and we send our vars (from get_dedined_vars()
) to itwoocommerce.blade.php
will call App\woocommerce_content(get_defined_vars())
===> HERE we lose data if we don't pass get_defined_vars()
as parameter
App\woocommerce_content()
is overrided from Woocommerce wp-content/plugins/woocommerce/includes/wc-template-functions.php
$args
, which are our datasApp\woocommerce_content()
will output correct Woocommerce template hierarchy, passing $args
to wc_get_template_part()
it calls\App
to \App\Controller
2.0.1
Notice
error about theme requiring header.php
and sidebar.php
as it's deprecated to be without since 3.0.0
, see roots/sage@1620
Theme without header.php is deprecated since version 3.0.0 with no alternative available. Please include a header.php/sidebar.php template in your theme. \wp-includes\functions.php
)@debug('dump')
@debug('hierarchy')
@debug('controller')
@debug
function print_filters_for( $hook = "" ) {
global $wp_filter;
if( empty( $hook ) || !isset( $wp_filter[$hook] ) )
return;
print "<pre>";
print_r( $wp_filter[$hook] );
print "</pre>";
}