-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoocommerce.php
41 lines (32 loc) · 1.28 KB
/
woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* The Template for displaying all WooCommerce posts
*/
if (!class_exists('Timber')) {
echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
return;
}
$context = Timber::context();
$context['sidebar'] = Timber::get_widgets('shop-sidebar');
if (is_singular('product')) {
$context['post'] = Timber::get_post();
$product = wc_get_product($context['post']->ID);
$context['product'] = $product;
// Get related products
$related_limit = wc_get_loop_prop('columns');
$related_ids = wc_get_related_products($context['post']->id, $related_limit);
$context['related_products'] = Timber::get_posts($related_ids);
// Restore the context and loop back to the main query loop.
wp_reset_postdata();
Timber::render('templates/_woocommerce/single-product.twig', $context);
} else {
$posts = Timber::get_posts();
$context['products'] = $posts;
if (is_product_category()) {
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$context['category'] = get_term($term_id, 'product_cat');
$context['title'] = single_term_title('', false);
}
Timber::render('templates/_woocommerce/archive.twig', $context);
}