Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Bugfix - missing $__env variable (#5)
Browse files Browse the repository at this point in the history
* Bugfix - missing $__env variable

* fix

* fix #2
  • Loading branch information
mejta authored and mmirus committed Aug 21, 2018
1 parent 1810954 commit 9be3fff
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```
```
19 changes: 16 additions & 3 deletions src/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 9be3fff

Please sign in to comment.