Roots Discourse

Sage 9, Sensei plugin, WooCommerce templating

woocommerce

#1

Hi!

Im trying to override a third party plugin, Sensei from WooCommerce with Sage. As others have done with WooCommerce I created a folder in resources, /resources/sensei/archive-course.php and in that put: <?php echo App\Template('sensei'); ?>
Then in my views folder, /resources/views/archive-course.blade.php. Tho I dont seem to be able to override it. Since its WooCommerce that have made the plugin and overriding it in the standard way is the same as with WooCommerce, I thought it would behave similar…

Im not sure what I am missing since Im fairly new to Sage and Blade in general. Any help is greatly appreciated!

Kr,
Jesper


#2

I haven’t heard of Sensei before, but I’d recommend adding this to your Sage project and see if it helps with replacing templates https://github.com/roots/sage-woocommerce.

Read the readme on there and apply that same stuff to the Sensei templates.


#3

@codepuncher So its been a while and Ive installed that and also been in contact with one of the developers. I think Im on the right track, tho I cant seem to be able to make it run my functions instead. I put a “woothemes-sensei.php” file as you can see in the image.

All Im trying at this point is getting it to load this file so that I can go from there and I think I will be alright. I cant see that the other plugin is doing anything different… Anything Im missing?

Im using visual studio code and xdebugger and can see it entering the other file but not mine. Below is the other plugin and breakpoints that hits.

Any help or pointers is greatly appreciated!


#4

Hi @Heichichi,

Adding it under vendor/roots/sage-sensei won’t make Sage load it automatically. For that, you would need to make it a Composer package, host it somewhere (like on Github or Packagist), and use Composer to install it in your theme (like with Sage WooCommerce).

Your first and simplest option is to skip all of that and just put your woothemes-sensei.php file in your theme’s app folder, and then modify this bit in your theme’s functions.php file to tell Sage to load it:

/**
 * Sage required files
 *
 * The mapped array determines the code library included in your theme.
 * Add or remove files to the array as needed. Supports child theme overrides.
 */
array_map(function ($file) use ($sage_error) {
    $file = "../app/{$file}.php";
    if (!locate_template($file, true, true)) {
        $sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
    }
}, ['helpers', 'setup', 'filters', 'admin', 'woothemes-sensei']);

I would start here to get things working.

If you later want to package your Sensei code to publish it to the world or make it more easily reusable for yourself, then you would need to look into the Composer stuff.


#5

Any progress, on this? i’m also looking to do the same. Otherwise i’m going to create my own composer package for sensei, sadly some function are different from woocommerce.


#6

That would be great to see a sage-sensei package! Packages like this would be so helpful.