Since I wrote my last post on setting up WooCommerce in Sage 9 things have changed once again. Sage 9 beta 3 has adjusted its structure and looks even more like a Laravel app. And WooCommerce has also been adjusted and since WooCommerce 3.0 several patches have been added. So let’s discuss the Sage 9 Beta 3 WooCommerce Setup shall we?
There are no longer template files anymore. That is, there are, but they are now all added under /resources/views . Not under templates anymore. Here is the structure now:
site/web/app/themes/sage/resources/views $ tree -L 2 . ├── 404.blade.php ├── archive-product.php ├── index.blade.php ├── layouts │ └── app.blade.php ├── page.blade.php ├── partials │ ├── comments.blade.php │ ├── content-page.blade.php │ ├── content-search.blade.php │ ├── content-single.blade.php │ ├── content.blade.php │ ├── entry-meta.blade.php │ ├── footer.blade.php │ ├── head.blade.php │ ├── header.blade.php │ ├── page-header.blade.php │ └── sidebar.blade.php ├── search.blade.php ├── single-product.php ├── single.blade.php ├── template-custom.blade.php ├── woocommerce │ ├── archive-product.php │ └── single-product.php └── woocommerce.blade.php
As you can see all .blade.php files are now under resources/views like they are in a Laravel app.
We still seem to need to add archive-product.php and single-product.php to make WooCommerce work properly and have the content we add for WooCommerce loaded there. These seem to work from the views directory or views/woocommerce. But we do now have a way to use Blade templating by making them load woocommerce.blade.php.
This we can do with a simple:
<?php echo App\Template('woocommerce'); ?>
WooCommerce Blade file
The woocommerce.blade.php file is where we do all our magic and CAN use Blade. For a basic display we add:
@extends('layouts.app') @section('content') @php(woocommerce_content()) @endsection
This so we can load the basic app layout and the general WooCommerce content using:
As you can see this is a great step forward integrating Blade into WooCommerce!