Skip to content

Commit e832699

Browse files
committed
Add WooCommerce support
1 parent afbaf8f commit e832699

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

app/setup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
add_theme_support('soil-nice-search');
3030
add_theme_support('soil-relative-urls');
3131

32+
/**
33+
* Declare WooCommerce support
34+
*/
35+
add_theme_support('woocommerce');
36+
3237
/**
3338
* Enable plugins to manage the document title
3439
* @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag

app/woocommerce.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App;
4+
5+
/**
6+
* WooCommerce Support
7+
*/
8+
add_filter('woocommerce_template_loader_files', function ($search_files, $default_file) {
9+
return filter_templates(array_merge($search_files, [$default_file, 'woocommerce']));
10+
}, 100, 2);
11+
add_filter('woocommerce_locate_template', function ($template, $template_name, $template_path) {
12+
$theme_template = locate_template("{$template_path}{$template_name}");
13+
return $theme_template ? template_path($theme_template) : $template;
14+
}, 100, 3);
15+
add_filter('wc_get_template_part', function ($template, $slug, $name) {
16+
$theme_template = locate_template(["woocommerce/{$slug}-{$name}", "woocommerce/${name}"]);
17+
return $theme_template ? template_path($theme_template) : $template;
18+
}, 100, 3);

resources/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
if (!locate_template($file, true, true)) {
5959
$sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
6060
}
61-
}, ['helpers', 'setup', 'filters', 'admin']);
61+
}, ['helpers', 'setup', 'filters', 'admin', 'woocommerce']);
6262

6363
/**
6464
* Here's what's happening with these hooks:

0 commit comments

Comments
 (0)