From f2f5c709fbe06a288c2ae8ec1d3101e34c9bdd3c Mon Sep 17 00:00:00 2001 From: Mtxz Date: Tue, 17 Jul 2018 18:32:24 +0200 Subject: [PATCH 1/3] - support for woocommerce 3.4.3 (in progress) --- README.md | 19 +++++++++++++++---- your-sage-theme/app/filters.php | 26 +++++++++++++++++++++++--- your-sage-theme/app/helpers.php | 2 +- your-sage-theme/app/setup.php | 11 +++++++---- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f670f55..453f837 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# Sage 9.0.1 Woocommerce (3.3.5) Integration -How to use Woocommerce (3.3.5) with Sage 9.0.1 (Blade + SoberWP controllers) +# Sage 9.0.1 Woocommerce (3.4.3) Integration +How to use Woocommerce (3.4.3) with Sage 9.0.1 (Blade + SoberWP controllers), WP 4.9.7 (17/07/2018) ## Features - Includes: @@ -21,19 +21,30 @@ How to use Woocommerce (3.3.5) with Sage 9.0.1 (Blade + SoberWP controllers) - [github](https://github.com/MarekVrofski/Sage-Woocommerce) (much thanks again to [@MarekVrofski](https://github.com/MarekVrofski/) for his improvements) ## Changelog -- 09/07/2018 - test in progress +- 17/07/2018 - test still in progress - Sage 9.0.1 - Woocommerce 3.4.3 - [SoberWP controller 9.0.0-beta.4](https://github.com/soberwp/controller/releases) ([Sage 9.0.1 uses SoberWP controller 9.0.0-beta.4](https://github.com/roots/sage/blob/master/composer.json), not latest [SoberWP controller 2.0.1](https://github.com/soberwp/controller/releases)) - PHP 7.2.5 (fpm), Nginx, Debian (& Windows 10 - Laragon PHP 7.1) + - Something changed, Woocommerce didn't use anymore our `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` - 18/05/2018 - tested with - Woocommerce 3.3.5 - Sage 9.0.1 - [SoberWP controller 9.0.0-beta.4](https://github.com/soberwp/controller/releases) ([Sage 9.0.1 uses SoberWP controller 9.0.0-beta.4](https://github.com/roots/sage/blob/master/composer.json), not latest [SoberWP controller 2.0.1](https://github.com/soberwp/controller/releases)) - PHP 7.2.5 (fpm), Nginx, Debian (& Windows 10 - Laragon PHP 7.1) - + +## What I usualy do + +**Editing shop page** + +- I prefer not use the default woocommerce shop page. So I do my own template/controller (wp_query) and pagination (will publish soon, really easy) and redirect official shop page to this custom one. As this template is mostly managed by our App\woocommerce_content() and sub-templated. But it is doable, updating woocommerce_content and related sub-template. Longer maybe ? Cleaner for sure :) +- Single product page, my account, checkout templates should be easy to override +- I'll publish another repo with "how to's" and helpers for Sage (time, time, time...) + + ## How ### Blade for Woocommerce +- Since V1.1, we force `/resources/views/woocommerce.blade.php` as first in woocommerce default template file array (see changelog) - we add_filter on - `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 files diff --git a/your-sage-theme/app/filters.php b/your-sage-theme/app/filters.php index 3db863f..157f30b 100644 --- a/your-sage-theme/app/filters.php +++ b/your-sage-theme/app/filters.php @@ -2,9 +2,29 @@ namespace App; +/** + * Use our woocommerce.blade.php as default woocommerce root template + * 17.07.18: tested and required for Woocommerce 3.4.3 integration with sage 9.0.1 (WP 4.9.7) + * + * It seems that since woocommerce 3.4.X (not sure since, but was not needed on my latest tests): + * - woocommerce don't see our /ressources/views/woocommerce.blade.php + * - it search and correctly find a /ressources/woocommerce.php + * And so, you got your resources/views/content-single-product.blade.php working, but not using your blade app main layout + * - here we put the path of our 'woocommerce.blade.php' as first into the Woocommerce default template array + * - wp-content/plugins/woocommerce/includes/class-wc-template-loader.php l68 template_loader() calls -> + * - wp-content/plugins/woocommerce/includes/class-wc-template-loader.php l129 get_template_loader_files() that uses 'woocommerce_template_loader_files' filter + * - but in template_loader() the call to locate_template() fails to find our woo.blade.php... only a /resources/woocommerce.php because of STYLESHEETPATH & TEMPLATEPATH templating variables (wp-includes/default-constants.php l344) + * + * Added a comment here: https://github.com/roots/sage/issues/1429 + */ +add_filter( 'woocommerce_template_loader_files', function ( $default_file ) { + $default_file[] = 'views/woocommerce.blade.php'; + return $default_file; +}, PHP_INT_MAX ); + /** * Render page using Blade (and get data from controller from sage/template/{$class}/data filter) - * 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 + * 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 * Changed: fix for single-product.php and archive-product to get correct template * todo: is there other "woocommerce root" template that should be hot fixed here ? */ @@ -28,7 +48,7 @@ /** * Render page using Blade - * 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 + * 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 * Changed: locate blade or php template file and render it * Triggers just before woocommerce actually render PHP template, but return blade and null, or php template like woocommerce would do * wp-content/plugins/woocommerce/includes/wc-core-functions.php:l158 @@ -65,7 +85,7 @@ /** * Render woocommerce template parts using Blade - * 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 + * 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 * Changed: Woocommerce support to use resources/views/woocommerce/* templates when using template parts * (wc_get_template_part & template_include filters will search for .blade.php) */ diff --git a/your-sage-theme/app/helpers.php b/your-sage-theme/app/helpers.php index f0cbefe..39313ee 100644 --- a/your-sage-theme/app/helpers.php +++ b/your-sage-theme/app/helpers.php @@ -1,7 +1,7 @@ - + From 42c0ae825168143fe90732a89dc0f52acb2098ae Mon Sep 17 00:00:00 2001 From: Mtxz Date: Tue, 17 Jul 2018 19:26:08 +0200 Subject: [PATCH 2/3] readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 453f837..fd0ab1e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Sage 9.0.1 Woocommerce (3.4.3) Integration 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. + ## Features - Includes: - Blade Woocommerce templates From 4bbc8b839df14809e62fea48a8f2d5353fb77ac0 Mon Sep 17 00:00:00 2001 From: Mtxz Date: Wed, 18 Jul 2018 01:25:40 +0200 Subject: [PATCH 3/3] better way to force woocommerce.blade.php as default woocommerce template + readme --- README.md | 3 ++- your-sage-theme/app/filters.php | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fd0ab1e..2582946 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Check dev branches for latest updates. - [discourse.roots.io](https://discourse.roots.io/t/woocommerce-blade-sage-9/8449/17) - [discourse.roots.io](https://discourse.roots.io/t/any-working-example-of-sage-9-latest-sage-9-0-0-beta-4-with-woocommerce-3-1-1/10099/17) - [github](https://github.com/MarekVrofski/Sage-Woocommerce) (much thanks again to [@MarekVrofski](https://github.com/MarekVrofski/) for his improvements) - + - [github sage PR](https://github.com/roots/sage/pull/1923) + ## Changelog - 17/07/2018 - test still in progress - Sage 9.0.1 diff --git a/your-sage-theme/app/filters.php b/your-sage-theme/app/filters.php index 157f30b..d847148 100644 --- a/your-sage-theme/app/filters.php +++ b/your-sage-theme/app/filters.php @@ -14,13 +14,13 @@ * - wp-content/plugins/woocommerce/includes/class-wc-template-loader.php l68 template_loader() calls -> * - wp-content/plugins/woocommerce/includes/class-wc-template-loader.php l129 get_template_loader_files() that uses 'woocommerce_template_loader_files' filter * - but in template_loader() the call to locate_template() fails to find our woo.blade.php... only a /resources/woocommerce.php because of STYLESHEETPATH & TEMPLATEPATH templating variables (wp-includes/default-constants.php l344) + * - our override filter_templates() method will return a correct path for woocommerce.blade.php * * Added a comment here: https://github.com/roots/sage/issues/1429 */ -add_filter( 'woocommerce_template_loader_files', function ( $default_file ) { - $default_file[] = 'views/woocommerce.blade.php'; - return $default_file; -}, PHP_INT_MAX ); +add_filter( 'woocommerce_template_loader_files', function ( $templates, $default_file ) { + return filter_templates(array_merge($templates, array_filter([$default_file, 'woocommerce']))); +}, PHP_INT_MAX, 2 ); /** * Render page using Blade (and get data from controller from sage/template/{$class}/data filter)