Sage 10 and roots/sage-woocommerce compatibility

Hello, I’ve being wroking on porting roots/sage-woocommerce to Sage 10 and so far it’s working out well except that I am stuck trying to find the proper way to handle a situation with one of the filter. If someone who knows better than me the api of sage or acorn, maybe they could point me in the right direction?

The wc_get_template filter in roots/sage-woocommerce returns and empty view if there’s a template found in the the theme files. How would get_stylesheet_directory() . '/index.php' be translated in Sage 10?

I assume I would like to do something like this and set an empty view, but I am not sure how to set a view like this filter does by assigning it to app['sage.view'] = ... Something like app('sage')->setView($view); for example?

This is where I am stuck:

add_filter('wc_get_template', function ($template, $template_name, $args) {
        $name = WC()->template_path() . $template_name;
        $theme_template = locate_template(app('sage.finder')->locate($name));

        // return theme filename for status screen
        if (is_admin() &&
            ! wp_doing_ajax() &&
            function_exists('get_current_screen') &&
            get_current_screen() &&
            get_current_screen()->id === 'woocommerce_page_wc-status') {
            return $theme_template ? : $template;

        // return empty file, output already rendered by 'woocommerce_before_template_part' hook
        return $theme_template ? get_template_directory() . '/index.php' : $template;
    }, 100, 3);

My repo with the other working filters is here.

I would be happy to submit a PR once I solved this.

I’d really like to use the view composer on my new project. Sage 10 looks so great! :slight_smile:


Updated to includean empty template in the package itself. You would now need to add a namespace to Sage config/view.php file. Seems to work all right. :boom:

    'namespaces' => [
        'SageWoocommerce' => get_theme_file_path('/vendor/roots/sage-woocommerce/src/resources/views'),

This topic was automatically closed after 42 days. New replies are no longer allowed.