I’ve been trying every example on the forum without much luck.
Some of the examples duplicate the woocommerce content over and over again (in my case), some just don’t work.
I’ve ended with a setup that seams to work, but not sure how to overwrite additional files from woo.
// app/setup.php
add_theme_support('woocommerce');
// app/woocommerce.php
<?php
namespace App;
/**
* WooCommerce Support
*/
add_filter('woocommerce_template_loader_files', function ($search_files, $default_file) {
return filter_templates(array_merge($search_files, [$default_file, 'woocommerce']));
}, 100, 2);
add_filter('woocommerce_locate_template', function ($template, $template_name, $template_path) {
$theme_template = locate_template("{$template_path}{$template_name}");
return $theme_template ? template_path($theme_template) : $template;
}, 100, 3);
add_filter('wc_get_template_part', function ($template, $slug, $name) {
$theme_template = locate_template(["woocommerce/{$slug}-{$name}", "woocommerce/${name}"]);
return $theme_template ? template_path($theme_template) : $template;
}, 100, 3);
// resources/functions.php
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', 'woocommerce']);
All from https://github.com/roots/sage/pull/1923
// resources/views/woocommerce/archive-product.php
<?php echo App\Template('woocommerce');
// resources/views/woocommerce.blade.php
@extends ('layouts.app')
@section ('content')
@php (woocommerce_content())
@stop
Does anyone have a better setup?
Can I make any improvements to the current setup?