diff --git a/examples/views/archive-product.blade.php b/examples/resources/views/woocommerce/archive-product.blade.php similarity index 100% rename from examples/views/archive-product.blade.php rename to examples/resources/views/woocommerce/archive-product.blade.php diff --git a/examples/views/single-product.blade.php b/examples/resources/views/woocommerce/single-product.blade.php similarity index 100% rename from examples/views/single-product.blade.php rename to examples/resources/views/woocommerce/single-product.blade.php diff --git a/readme.md b/readme.md index c695535..39ce821 100644 --- a/readme.md +++ b/readme.md @@ -4,20 +4,21 @@ This package enables WooCommerce integration with Sage 9 themes and Blade templa ## Installation -Install the package in your theme folder: +Install the package **in your theme folder**: ```bash +cd wp-content/themes/your-sage-theme-folder composer require roots/sage-woocommerce ``` ## Usage -Create `woocommerce` folder in `/resources/views` folder of your theme and place there any template used by WooCommerce with `.blade.php` extension. This template will be loaded instead of a template from the WooCommerce plugin. If you want to replace particular template, please have a look into plugin folder `woocommerce/templates` and use same folder structure and file name (and change the extension to `.blade.php`) as the original template. +Create `/resources/views/woocommerce` folder in your theme and place there any template used by WooCommerce with `.blade.php` extension. This template will be loaded instead of a template from the WooCommerce plugin. If you want to replace particular template, please have a look into plugin folder `woocommerce/templates` and use same folder structure and file name (and change the extension to `.blade.php`) as the original template. -By default, you will get an error message that themes without `header.php`, `footer.php` and `sidebar.php` are deprecated. You have to replace `single-product.php` and `archive-product.php` templates with your Blade template. You can find those two files in `/examples/views` folder of this package. The trick is not to use `get_header`, `get_footer` or `get_sidebar` functions, because it's handled differently with Blade. Instead of that, you can use actions: +By default, you will get an error message that themes without `header.php`, `footer.php` and `sidebar.php` are deprecated. You have to replace `single-product.php` and `archive-product.php` templates with your Blade template. You can find those two files in `/examples/resources/views/woocommerce` folder of this package. The trick is not to use `get_header`, `get_footer` or `get_sidebar` functions, because it's handled differently with Blade. Instead of that, you can use actions: ```php do_action('get_header', 'shop'); do_action('get_sidebar', 'shop'); do_action('get_footer', 'shop'); -``` +``` \ No newline at end of file diff --git a/src/woocommerce.php b/src/woocommerce.php index f508963..77ce2cc 100644 --- a/src/woocommerce.php +++ b/src/woocommerce.php @@ -14,11 +14,24 @@ add_filter('wc_get_template_part', function ($template) { $theme_template = locate_template('woocommerce/' . str_replace(WC_ABSPATH . 'templates/', '', $template)); - return $theme_template ? template_path($theme_template) : $template; - }, 100, 1); + + if ($theme_template) { + echo template($theme_template); + return get_stylesheet_directory() . '/index.php'; + } + + return $template; + }, PHP_INT_MAX, 1); add_filter('wc_get_template', function ($template, $template_name, $args) { $theme_template = locate_template('woocommerce/' . $template_name); + + // Don't render template when used in REST + if ($theme_template && !(defined('REST_REQUEST') && REST_REQUEST)) { + echo template($theme_template, $args); + return get_stylesheet_directory() . '/index.php'; + } + return $theme_template ? template_path($theme_template, $args) : $template; - }, 100, 3); + }, PHP_INT_MAX, 3); }