Latest Sage 9, Blade, and WooCommerce

Hi,
I’m trying to implement WooCommerce with the latest dev-master of Sage 9. I’ve followed the various solutions here (Woocommerce & Blade (Sage 9)) without luck. Is there something new needed now that views are in resources/views?

I’ve tried putting woocommerce.blade.php in resources/views and in resources/views/woocommerce and the template doesn’t seem to load. I get the WooCommerce header.php error no matter what I do.

Thanks!

Hey,
I haven’t tried the latest version yet, but the logic which worked on the beta 2 was that woocommerce will load template (single-product.php or archive-product.php_) from your theme’s folder and then you would echo Sage’s get template function in it.

WooCommerce doesn’t recognize blade files so you would need to hack your way to them by calling echo App\Template('woocommerce'); function inside basic php file (in this case archive-product.php and single-product.php). This should work since the template function is one of the default function in Sage.

There shouldn’t be any problems in theory but as I said haven’t have time to try the new version of Sage yet :confused:

There was a mention about new filter in WooCommerce which you could use to get template file but I haven’t got time to figure that out yet. You can try if you can get this working by using that: https://github.com/roots/sage/issues/1807 (the last comment from QWp6t).

Thanks, this helped me think about the problem more clearly. I removed the Woocommerce templates I’d created and started over and made some progress.

I have the following in resources/views/woocommerce/archive-product.php and resources/views/woocommerce/single-product.php

<?php echo App\Template('woocommerce');

And when I try to view any shop page, I get a 504 Gateway Time-out error.

So it seems to me like something’s changed since Beta 2. I’ll keep digging but any insight from the team would be great.

EDIT NEVER MIND I’M AN IDIOT:

Here’s what I had in resources/views/woocommerce.blade.php

@extends('layouts.app')

@section('content')
  @while(have_posts()) @php(the_post())
	@php(woocommerce_content())
  @endwhile
@endsection

The keener-eyed among you will notice that I left the while loop in there despite every piece of documentation on the subject saying to take it out.

Taking it out fixed the problem.

1 Like

My single-product.php in resources/views/woocommerce/ don’t seem to override the woocommerce one… But it works for archive-product.php.
Re-writting the woocommerce file (wp-plugins/) directly works.
any idea ?

Had to tweak template_include filter using (#sad):
if(str_contains($template, ‘single-product.php’)) {
$template = get_stylesheet_directory() . ‘/views/woocommerce/single-product.blade.php’;
}

Hello, we are trying to do this now with sage 9 and woocommerce 3.4.3, any help is suggested, thanks

What have you tried? What isn’t working?

Currently I have this setup:

sage/resources/views/woocommerce.blade.php
sage/resources/views/single-product.blade.php
sage/resources/views/archive-product.blade.php

All files have this code inside:

@extends('layouts.app')

@section('content') 
  @php(woocommerce_content()) 
@endsection

This seems to be working so far, however I will want to override more of the templates, is there any documentation that you have found that works best?

1 Like

Not to sound like a broken record, but have you tried to customize further templates and run into problems? Are you seeing errors?

The best advice I can give in any situation like this is to try.

For the love of god. Please post an example theme with overrides this is ridiculous

Hi, welcome to the Roots forum. Support here is supplied on a volunteer basis and is often best solicited with a kind word.

Since this topic was created in 2017 the Roots team has, with generous help from the community, created sage-woocommerce, a composer library add-in for Sage which simplifies WooCommerce integration. Its documentation should have the information you need. If not, please feel free to start a new topic and be sure to detail what you’ve tried, and any relevant code you’ve written.

5 Likes

Hi,
I’m trying to solve this and I think we have to look at the root of the problem, is it really sage9 and blade or just the file structure and file filter functions?

Is the problem that WooCommerce is looking for templates in theme-name/woocommerce but sage9 is storing our blade templates in theme-name/resources/views/woocommerce?