Skip to content

Commit

Permalink
Add a filter to support woocommerce third party plugin templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tombroucke authored and oxyc committed Jul 22, 2021
1 parent eb6ab53 commit d73fa35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ add_theme_support('wc-product-gallery-zoom');
add_theme_support('wc-product-gallery-lightbox');
add_theme_support('wc-product-gallery-slider');
```

## Filters

```php
/**
* Add support for WooCommerce Subscription templates.
*/
add_filter('sage-woocommerce/templates', function ($paths) {
$paths[] = WP_PLUGIN_DIR . '/woocommerce-subscriptions/templates/',
return $paths;
]);
```
15 changes: 11 additions & 4 deletions src/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,21 @@ protected function isWooCommerceTemplate(string $template): bool
*/
protected function relativeTemplatePath(string $template): string
{
$relativeTemplate = str_replace(\WC_ABSPATH . 'templates/', '', $template);
$defaultPaths = [
// WooCommerce plugin templates
\WC_ABSPATH . 'templates/',
];

if (is_child_theme()) {
// Let child theme overwrite parent theme templates
$relativeTemplate = str_replace(get_template_directory() . '/' . WC()->template_path(), '', $relativeTemplate);
// Parent theme templates in woocommerce/ subfolder.
$defaultPaths[] = get_template_directory() . '/' . WC()->template_path();
}

return $relativeTemplate;
return str_replace(
apply_filters('sage-woocommerce/templates', $defaultPaths),
'',
$template
);
}

/**
Expand Down

0 comments on commit d73fa35

Please sign in to comment.