Skip to content

Instantly share code, notes, and snippets.

@asecondwill
Last active June 20, 2017 13:09
Show Gist options
  • Save asecondwill/0727eda5dd6c548ac680 to your computer and use it in GitHub Desktop.
Save asecondwill/0727eda5dd6c548ac680 to your computer and use it in GitHub Desktop.
and the php
<?
$context = Timber::get_context();
$context['cats'] = Timber::get_terms('product_cat');;
if (is_singular('product')) {
$context['post'] = Timber::get_post();
$product = get_product( $context['post']->ID );
$context['product'] = $product;
add_action( 'mc_attributes', function($product){
$product->list_attributes();
});
add_action( 'mc_reviews', function($product){
return wc_get_template('single-product-reviews.php');
});
Timber::render('woo/single-product.twig', $context);
}else{
$posts = Timber::get_posts();
$products = [];
foreach ($posts as $post) {
$p= [];
$p['post'] = $post;
$p['product'] = get_product( $post->ID );
$products[] = $p;
}
$context['products'] = $products;
Timber::render('woo/products.twig', $context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment