{"id":13760129,"url":"https://github.com/mtx-z/Sage9-Woocommerce-Integration","last_synced_at":"2025-05-10T10:31:29.602Z","repository":{"id":168021483,"uuid":"133997822","full_name":"mtx-z/Sage9-Woocommerce-Integration","owner":"mtx-z","description":"How to use Woocommerce (3.4.3) with Sage 9.0.1 (Blade + SoberWP controllers), WP 4.9.7 (17/07/2018)","archived":false,"fork":false,"pushed_at":"2018-08-08T15:13:07.000Z","size":27,"stargazers_count":26,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-16T17:41:00.885Z","etag":null,"topics":["blade","controllers","override","rootsio","sage","sage9","soberwp","woocommerce","woocommerce3","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtx-z.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-18T19:50:58.000Z","updated_at":"2020-09-16T03:55:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"700d57b9-eb5c-4fcc-a630-8ed0849438f8","html_url":"https://github.com/mtx-z/Sage9-Woocommerce-Integration","commit_stats":null,"previous_names":["mtx-z/sage9-woocommerce-integration"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtx-z%2FSage9-Woocommerce-Integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtx-z%2FSage9-Woocommerce-Integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtx-z%2FSage9-Woocommerce-Integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtx-z%2FSage9-Woocommerce-Integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtx-z","download_url":"https://codeload.github.com/mtx-z/Sage9-Woocommerce-Integration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253401267,"owners_count":21902641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blade","controllers","override","rootsio","sage","sage9","soberwp","woocommerce","woocommerce3","wordpress"],"created_at":"2024-08-03T13:01:03.799Z","updated_at":"2025-05-10T10:31:29.329Z","avatar_url":"https://github.com/mtx-z.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Sage 9.0.1 Woocommerce (3.4.3) Integration\nHow to use Woocommerce (3.4.3) with Sage 9.0.1 (Blade + SoberWP controllers), WP 4.9.7 (17/07/2018)\n\nCheck dev branches for latest updates.\n\nCheck previous release if error with latest.\n\n## Features\n- Includes: \n  - Blade Woocommerce templates\n    - Override using default .php file, or rename to .blade.php to use blade (SoberWP controllers variable are available in both case)\n    - place your woocommerce templates overrides in /your-sage-theme/resources/views/woocommerce/\n      - eg: `/plugins/woocommerce/templates/content-single-product.php` =\u003e `/your-sage-theme/resources/views/woocommerce/content-single-product.blade.php`\n      - eg: `/plugins/woocommerce/templates/single-product/meta.php` =\u003e `/your-sage-theme/resources/views/woocommerce/single-product/meta.blade.php`\n      - still need test for sub-templates, but seems to works with `meta.blade.php`\n  - SoberWP controllers with Woocommerce blade (or php) templates\n    - Get \\App global default Sage controller variables available in Woocommerce Blade templates\n    - Create custom controllers for Woocommerce templates with same Woocommerce/SoberWP template/naming hierarchy naming logic (eg: `single-product` controller for `single-product.blade.php` then `content-single-product.blade.php` template)\n  \n## Sources and supports\n- I haven't tested all yet, please feel free to report any bug or improvement in issues and I'll fix\n- Sources:\n  - [discourse.roots.io](https://discourse.roots.io/t/woocommerce-blade-sage-9/8449/17)\n  - [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)\n  - [github](https://github.com/MarekVrofski/Sage-Woocommerce) (much thanks again to [@MarekVrofski](https://github.com/MarekVrofski/) for his improvements)\n  - [github sage PR](https://github.com/roots/sage/pull/1923)\n  - [github](https://github.com/roots/sage-woocommerce)\n\n## Changelog\n- 17/07/2018 - test still in progress\n    - Sage 9.0.1\n    - Woocommerce 3.4.3\n    - [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))\n    - PHP 7.2.5 (fpm), Nginx, Debian (\u0026 Windows 10 - Laragon PHP 7.1)\n    - 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`\n- 18/05/2018 - tested with\n    - Woocommerce 3.3.5\n    - Sage 9.0.1\n    - [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))\n    - PHP 7.2.5 (fpm), Nginx, Debian (\u0026 Windows 10 - Laragon PHP 7.1)\n\n## What I usualy do\n\n**Editing shop page**\n\n- 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 :)\n- Single product page, my account, checkout templates should be easy to override\n- I'll publish another repo with \"how to's\" and helpers for Sage (time, time, time...)\n\n\n## How\n### Blade for Woocommerce\n- Since V1.1, we force `/resources/views/woocommerce.blade.php` as first in woocommerce default template file array (see changelog)\n- we add_filter on \n  - `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)\n  - `wc_get_template_part`: edit woocommerce template method to look for blade files then php files\n  - `wc_get_template`: tell woocommerce to get template from `resources/views/`\n- `single-product.php` and `archive-product.php` includes `woocommerce.blade.php` template\n- `woocommerce.blade.php` calls our overrided `App\\woocommerce_content(get_defined_vars())` that output Woocommerce content\n\n### SoberWP controllers data for Woocommerce\n- SoberWP `Controller.php` (`new Loader()`) will parse all controller and methods and store them using \"slugified\" `$template` name as keys in `$this-\u003einstance` (the `controller::class` object is stored)\n- SoberWP `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 want\n- Sage/WP will normally get `single-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 rules\n- Sage will `apply_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-\u003erender` (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)\n- At the moment, (we are in `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 HERE\n- from here, we call `helpers::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 it\n- `woocommerce.blade.php` will call `App\\woocommerce_content(get_defined_vars())` ===\u003e HERE we lose data if we don't pass `get_defined_vars()` as parameter\n    - `App\\woocommerce_content()` is overrided from Woocommerce `wp-content/plugins/woocommerce/includes/wc-template-functions.php`\n    - to add a parameter to pass `$args`, which are our datas\n- `App\\woocommerce_content()` will output correct Woocommerce template hierarchy, passing `$args` to `wc_get_template_part()` it calls\n\n## Todo\n- few test with [SoberWP 2.0.1](https://github.com/soberwp/controller/releases)\n  - Few errors as default Namespace changes from `\\App` to `\\App\\Controller`\n  - should be fixable when Sage update to SoberWP Controller `2.0.1`\n- Lot of Woocommerce features and templates (and controller variables passing) to test...\n- controllers variables to sub templates (\u0026 nested)\n\n## Careful\n- Absolutely not tested with all Woocommerce templates and features\n  - Checkout, My accounts, Emails, nested templates, Woocommerce plugins templates... need more tests\n- **Test** before usage in production (I do and it runs smoothly tho, but it's not a complex store)\n- still WIP, issues and improvement reports are welcomed !\n- `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](https://github.com/roots/sage/issues/1620) \n  - (`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`)\n\n## DEBUG\n#### SoberWP\n```\n@debug('dump')\n@debug('hierarchy')\n@debug('controller')\n@debug\n```\n\n#### get hooked methods for given filter\n```\nfunction print_filters_for( $hook = \"\" ) {\nglobal $wp_filter;\n    if( empty( $hook ) || !isset( $wp_filter[$hook] ) )\n        return;\n\n    print \"\u003cpre\u003e\";\n    print_r( $wp_filter[$hook] );\n    print \"\u003c/pre\u003e\";\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtx-z%2FSage9-Woocommerce-Integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtx-z%2FSage9-Woocommerce-Integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtx-z%2FSage9-Woocommerce-Integration/lists"}