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?

Sage Views

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.

WooCommerce Templates

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:

 @php(woocommerce_content())

As you can see this is a great step forward integrating Blade into WooCommerce!

6 Responses

  1. Hey Jasper! I think your post of alllllll the many posts on woocommerce integrating with sage 9 is the most accurate by far. When implementing your recommendation, i get a 504 Gateway Time-out error on my single product and archive product pages… any thoughts on why that might be?

    Thanks man!

    1. Thanks for the complement Kenny! I would check if your PHP settings for php_max_execution_time and php_memory_limit and make sure they suffice. In Trellis they can easily be adjusted / upped when need be.

  2. Thanks so much for summarizing this, getting crazy trying to make sense of all these threads in discourse.

    In your previous blog you mentioned how to get rid of notices like “header.php missing”. Does that still apply with the recent changes in Sage?

    I tried adding empty files like header.php and so on in the theme root, or in resources/views, but the debug error messages are still shown. Does this work for you? Thanks!

  3. Jasper, thanks a lot for putting together this guide – it helped a lot.

    However I was still having issues, while using Sage 9 – beta 4. I was getting the “header.php missing” error. The solution for me was to place `archive-product.php` & `single-product.php` under the `resources/` directory (not under `resources/views/`). So these files now actually sit next to `index.php`. So far it works fine, I will post an update if it I face further issues.

    I didn’t try Udo’s solution, but it probably works in a similar fashion with mine.

Leave a Reply to Jasper Cancel reply

Your email address will not be published. Required fields are marked *