Woocommerce & Blade (Sage 9)

Hey @kalenjohnson

How do I override Woocommerce template files with my theme’s blade files?

Now I’m overriding those by adding .php file (not blade file) inside templates folder. But this way it won’t load my base layout at all.

All I would need is to override archive-products.php and single-product.php with my own blade files inside theme/templates folder.

1 Like

@emilsgulbis posted a way to use blade templates for WooCommerce. (https://github.com/roots/sage/issues/1807 ).

…you should create 2 files in templates/woocommerce - archive-product.php and single-product.php and add only

<?php echo App\Template('woocommerce'); to them. Then in templates/woocommerce add woocommerce.blade.php that contains @extends('layouts.base') @section('content') @php(woocommerce_content()) @endsection

The only thing I did different was to place woocommerce.blade.php file inside theme/template folder instead of theme/template/woocommerce.

6 Likes

This works for me. I have also placed woocommerce.blade.php out side the woocommerce folder, but inside the templates folder/

2 Likes

Did anyone of you guys figure out how to access variables from the controller in your woocommerce templates?
I posted another topic here Controller and WooCommerce where @kalenjohnson explained that the problem is that the template files are not blade templates, and the controller only works with blade templates.

Did anyone stumble upon the same issue?

1 Like

Hey Guys, I’m trying to do the same with latest Sage 9 release but it doesn’t work with blade templates.

The “normal override” works (woocommerce/archive-product.php) though I have no base layout so it’s not really an option. I did try many solutions (they all date from 2017 in alpha of beta version) to have woocommerce.blade.php, but without success.

Here’s what I tried so far:
The above solution from Eljas



https://roots.io/using-woocommerce-with-sage/ (from sage 8)

Does anyone have a solution for this?

Thank you!

I would highly recommend @hambos22 sage 9 fork for integrating WooCommerce with Sage 9 and Blade: https://github.com/hambos22/sage-woo

3 Likes

I am bringing this thread back to life as I’ve searched and experimented with nearly every option I’ve discovered in this discourse to be able to override template files with Sage 9 but no luck.

Has anyone found an easy solution to this yet? I don’t exactly want to start over using that fork.

1 Like

I made a composer package out of the solution I used on some projects I did a while ago. Feel free to test it out. Have not had time to test it out on a fresh Sage 9 project. Not sure I like that the package looks everywhere for templates anymore, but the original idea was that woocommerce templates should work just like other templates, and that I also could put templates in a plugin.

https://packagist.org/packages/kimhf/sage-woocommerce-support

5 Likes

Thank you for providing this.

It appears to install perfectly. I haven’t had a lot of time to play with it yet but upon initial installation it appears to duplicate the header of a single-product page and completely removes everything else related to WooCommerce.

Here are a couple files I created as you mentioned in the docs but modifying the files presents no change to the single product pages:

Always speaking too soon…
Once I start putting together my own partials for WooCommerce the pages start coming together.

I was under the assumption that the standard WooCommerce pages would appear as default out of the box until I started overwriting them with my own template overrides.

If you start out with something like this in single-product.blade.php

@php
/**
 * The Template for displaying all single products
 *
 * @see 	    https://docs.woocommerce.com/document/template-structure/
 * @version     1.6.4
 */
@endphp

@extends('layouts.app')

@section('content')
    @php
		/**
		 * woocommerce_before_main_content hook.
		 *
		 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
		 * @hooked woocommerce_breadcrumb - 20
		 */
		do_action( 'woocommerce_before_main_content' );
    @endphp

    @while ( have_posts() )
      @php
      the_post();
      wc_get_template_part( 'content', 'single-product' );
      @endphp
    @endwhile

    @php
		/**
		 * woocommerce_after_main_content hook.
		 *
		 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
		 */
		do_action( 'woocommerce_after_main_content' );
    @endphp

    @php
		/**
		 * woocommerce_sidebar hook.
		 *
		 * @hooked woocommerce_get_sidebar - 10
		 */
		do_action( 'woocommerce_sidebar' );
    @endphp
@endsection

then it should definitely load the default woocommerce templates, but without the duplicate header that get_header( ‘shop’ ); caused in the default single-product.php

@KimH

Have you had any luck with comments as reviews for WooCommerce with Sage 9?

I’m able to display this at the top of product pages:
image

But the area lower on the product page where it displays the 7 reviews displays them as comments and the comment/review form doesn’t give the option to choose a star rating when adding a review. (The stars exist because this is previous site being revamped).

I have all the options turned on in WooCommerce and WP to allow comments and reviews.

I can’t find much info on this. If you have any ideas that would be great.

1 Like

Still having trouble with this. Anybody have any helpful tips?

Does it display 12345 instead of the stars? Then you can style it to stars!

No, no.

I have everything enabled to activate reviews. At the top of the single product pages I see the review rating and the amount of reviews:

image

Lower on the page where you would normally leave a review is set to leave a comment:

In the past and with other themes this comment section would turn into a reviews section allowing for users to give a rating and leave a review.

I can’t figure out how to change this within Sage to have it use WooCommerce reviews instead of WordPress comments.

This is a long shot but depending on how old your copy of Sage is, you could be running into this problem where poorly written plugin styles aren’t enqueued properly.

You could check if your copy of Sage includes these commits.

Thanks for the response. I don’t believe that’s the issue here. I’m all up to date on the theme. WooCommerce is working great. The review star ratings are appearing everywhere they should. It’s just that the comments area for single products are just that… comments. They’re not being transformed to reviews like I’m use to in the past.

Something I just discovered:

If I copy the code from “single-product-reviews.php” from the WooCommerce plugin directory and replace the code in the “comments.blade.php” then I see the following (after a bunch of debug errors):

Please excuse my lack for the correct terms but it appears Sage is not setup to allow WooCommerce reviews to override the default WordPress comments?

So now my Sage9 ‘comments.blade.php’ file looks like this:

I know there must be a better way of doing this but this is working for me for now.
It returns the results fine like this:

Jup, that seems right. I think that’s how mine looks!

1 Like