Righto here’s a quick explanation of how I managed to get WooCommerce to work with the Roots Sage 9 framework.

Firstly we need to create a woocommerce folder, I’m assuming we have already setup the Roots Sage 9 package, so navigate into the ‘/resources/‘ folder in the Roots Sage package and create a new directory in there called ‘woocommerce’ using your preferred method of creating folders/directories.

Next up we need a couple of files for our woocommerce templates to utilize. I’ve setup two seperate files, one for the product index pages and a seperate one for the individual product templates. You don’t necessarily have to have two, you can have just one and use the woocommerce actions and hooks to organize the data, or as I have here you can split them into templates as per the usual WordPress conventions.

Anyway lets not worry about that for the moment.
Next up I’ve created the first file, named ‘archive-product.php’ which will be the product index page (or pages). Then I need to add the following code to enable the template via the App controller (if thats he right word):

<?php $template = 'woocommerce';
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
    return apply_filters("sage/template/{$class}/data", $data, $template);
}, []);
echo App\Template($template, $data); ?>

Add this code into each template file you create and you’ll be good to go!

Leave a Reply

Privacy & more..

Cookie Consent Policy