Skip to content

Commit

Permalink
Update documentation and Changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Oct 10, 2020
1 parent 415002f commit 72a724b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## 0.6.0

- Improved internal handling for loading the internal `Product` class.
- Improved when this integration applies Product classes and Product Iterators to single posts and lists of posts. This should make it easier to have collections of WooCommerce products and other WordPress post types on the same page. Internally, this integration now uses a Class Map for the `product` post type. This means that you can also [extend](https://timber.github.io/docs/guides/extending-timber/) this integration’s `Timber\Integrations\WooCommerce\Product` class with your own `Product` class.
- Improved default **archive-product.twig** template and added default templates for **loop/loop-start.twig** and **loop/loop-end.twig**.
- Added a `$context` parameter to the `render_default_template()` function.
- Added a `post` variable to the context in Twig template partials.
- Added a default **checkout/form-checkout.twig** template.
- Added a `$context` parameter to the `render_default_template()` function. When you pass a context to this function, it will be merged with Timber’s default context.
- Added a `post` variable to the context in [Twig template partials](https://github.com/mindkomm/timber-integration-woocommerce/blob/master/docs/usage.md#automatic-twig-partial-selection).
- Fixed a bug when calling `Timber\Post::__construct()` messed up the `$product` global.

## 0.5.3.1 - 2020-07-29
Expand Down
20 changes: 19 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Read on if you want to know how you can override WooCommerce’s default templat

A **woocommerce.php** file that is placed into the root of your theme has priority over all other templates that you place in the `woocommerce/` folder of your theme. For example, **woocommerce.php** will take precedence over **woocommerce/archive-product.php**. If you use this file, WooCommerce will always use this file to render shop templates.

Add a file `woocommerce.php` to the root your theme with the following contents:
Add a file **woocommerce.php** to the root your theme with the following contents:

```php
<?php
Expand All @@ -84,6 +84,24 @@ Timber\Integrations\WooCommerce\WooCommerce::render_default_template();

The function `render_default_template()` makes it possible for you to render the default files used by WooCommerce. If you have more complex functionality that you need to apply, you can also copy the contents of the `render_default_template()` function into **woocommerce.php** directly and adapt it there.

If you want to add additional context variables to your shop pages, you can either use the `timber/context` filter or pass in a context directly to `render_default_template()`

**woocommerce.php**

```php
<?php

use Timber\Integrations\WooCommerce\WooCommerce;

$context = [
'shop_data' => 'Add data that will be added to WooCommerce shop pages only',
];

WooCommerce::render_default_template( $context );
```

The `$context` that you pass in here will be merged with the default Timber context.

## Optional: copy default templates to your theme

In the **defaults** folder of the integration, you’ll find [default Twig templates](https://github.com/MINDKomm/timber-integration-woocommerce/tree/master/defaults) for a couple of WooCommerce templates. They are examples for how you could translate templates from PHP to Twig.
Expand Down
40 changes: 15 additions & 25 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,45 +112,35 @@ What is the difference between `post` and `product` in the example above?

## WooCommerce context

The integration adds some context variables to the global Timber context. When you access the context through `Timber::get_context()`, you’ll get access to the following variables:
The integration adds some context variables to the global Timber context. When you access the context through `Timber::get_context()`, you’ll get access to certain variables.

### Global context

Global context variables are always available.

#### cart

The [WooCommerce cart object](https://docs.woocommerce.com/wc-apidocs/class-WC_Cart.html).
- `cart` – The [WooCommerce cart object](https://docs.woocommerce.com/wc-apidocs/class-WC_Cart.html).

### Template based context

In addition to the global context, you’ll have other context variables available based on the template file you’re currently working with.

#### post

Will be an instance of `Timber\Product` when a singular product page is displayed (`is_singular('product')`). If the [shop page](https://docs.woocommerce.com/document/woocommerce-pages/) is displayed, it will be a `Timber\Post` with that page as the contents.

#### term

Will be set when a shop taxonomy term is displayed (when [`is_product_taxonomy()`](https://docs.woocommerce.com/wc-apidocs/function-is_product_taxonomy.html) applies).

**views/woocommerce/archive-product.twig**

```twig
{% if term.description %}
<div class="description">{{ term.description }}
{% endif %}
```
- `post` – Will be an instance of `Timber\Product` when a singular product page is displayed (`is_singular('product')`). If the [shop page](https://docs.woocommerce.com/document/woocommerce-pages/) is displayed, it will be a `Timber\Post` with that page as the contents.
- `term` – Will be set when a shop taxonomy term is displayed (when [`is_product_taxonomy()`](https://docs.woocommerce.com/wc-apidocs/function-is_product_taxonomy.html) applies).

#### title
**views/woocommerce/archive-product.twig**

Title to display on archive pages. Result of [woocommerce_page_title()](https://docs.woocommerce.com/wc-apidocs/function-woocommerce_page_title.html).
```twig
{% if term.description %}
<div class="description">{{ term.description }}
{% endif %}
```
- `title` – Title to display on archive pages. Result of [woocommerce_page_title()](https://docs.woocommerce.com/wc-apidocs/function-woocommerce_page_title.html).

**views/woocommerce/archive-product.twig**
**views/woocommerce/archive-product.twig**

```twig
<h1 class="heading-1">{{ title }}</h1>
```
```twig
<h1 class="heading-1">{{ title }}</h1>
```

## Hooks

Expand Down
2 changes: 1 addition & 1 deletion lib/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function init( $args = array() ) {
* Setup classes Timber should use when in WooCommerce context.
*/
public function setup_classes() {
// Use a custom post class to for all WooCommerce product posts.
// Use a custom post class for all WooCommerce product posts.
add_filter( 'Timber\PostClassMap', array( $this, 'set_product_class' ) );

// Set a custom iterator to correctly set the $product global.
Expand Down

0 comments on commit 72a724b

Please sign in to comment.