Created
April 3, 2017 15:57
-
-
Save melissajclark/0c79afb640ec8f140c0ff861e401f12e to your computer and use it in GitHub Desktop.
woocommerce page with sections for product categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The WooCommerce Template | |
* | |
* This is the template that displays all WooCommerce pages by default. | |
* | |
* @package THEMENAME | |
*/ | |
get_header(); ?> | |
<?php if ( is_singular('product') ) : ?> | |
<?php woocommerce_content(); ?> | |
<?php elseif ( is_product_category() ) : ?> | |
<header class="entry-header hero-plain"> | |
<div class="innerContainer"> | |
<h1 class="entry-title"><?php woocommerce_page_title(); ?></h1> | |
<?php | |
/** | |
* woocommerce_archive_description hook. | |
* | |
* @hooked woocommerce_taxonomy_archive_description - 10 | |
* @hooked woocommerce_product_archive_description - 10 | |
*/ | |
do_action( 'woocommerce_archive_description' ); | |
?> | |
</div> | |
</header> | |
<?php if ( have_posts() ) : ?> | |
<?php | |
/** | |
* woocommerce_before_shop_loop hook. | |
* | |
* @hooked woocommerce_result_count - 20 | |
* @hooked woocommerce_catalog_ordering - 30 | |
*/ | |
do_action( 'woocommerce_before_shop_loop' ); | |
?> | |
<?php woocommerce_product_loop_start(); ?> | |
<?php woocommerce_product_subcategories(); ?> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<a itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class('grid__Item card card__product'); ?> href="<?php the_permalink(); ?>"> | |
<div class="card__Content"> | |
<?php the_post_thumbnail(); ?> | |
<h3 class="card__Title"><?php the_title(); ?></h3> | |
<?php do_action( 'woocommerce_after_shop_loop_item_title'); ?> | |
<p><?php the_advanced_excerpt(); ?></p> | |
</div> | |
<div class="card__Button" aria-hidden="true"><?php esc_html_e('Find Out More'); ?></div> | |
</a> | |
<?php endwhile; // end of the loop. ?> | |
<?php woocommerce_product_loop_end(); ?> | |
<?php endif; ?> | |
<?php elseif ( is_shop() ) : ?> | |
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?> | |
<header class="entry-header hero-plain"> | |
<div class="innerContainer"> | |
<h1 class="entry-title"><?php woocommerce_page_title(); ?></h1> | |
<?php | |
/** | |
* woocommerce_archive_description hook. | |
* | |
* @hooked woocommerce_taxonomy_archive_description - 10 | |
* @hooked woocommerce_product_archive_description - 10 | |
*/ | |
do_action( 'woocommerce_archive_description' ); | |
?> | |
</div> | |
</header> | |
<?php endif; ?> | |
<?php | |
/** | |
* | |
* WooCommerce display content by category | |
* http://wordpress.stackexchange.com/questions/139196/display-all-products-by-category-with-woocommerce | |
* | |
*/ | |
?> | |
<?php $args = array( | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
); | |
$product_categories = get_terms( 'product_cat', $args ); | |
$count = count($product_categories); | |
if ( $count > 0 ){ | |
foreach ( $product_categories as $product_category ) { | |
echo '<h2 class="shop__categoryTitle"><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></h2>'; | |
$args = array( | |
'posts_per_page' => -1, | |
'tax_query' => array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => $product_category->slug, | |
'orderby' => 'menu_order', | |
) | |
), | |
'post_type' => 'product', | |
'orderby' => 'menu_order', | |
); | |
$products = new WP_Query( $args ); | |
echo "<section class='grid'>"; | |
while ( $products->have_posts() ) { $products->the_post(); ?> | |
<a itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class('grid__Item card card__product'); ?> href="<?php the_permalink(); ?>"> | |
<div class="card__Content"> | |
<?php the_post_thumbnail(); ?> | |
<h3 class="card__Title"><?php the_title(); ?></h3> | |
<?php do_action( 'woocommerce_after_shop_loop_item_title'); ?> | |
<p><?php the_advanced_excerpt(); ?></p> | |
</div> | |
<div class="card__Button" aria-hidden="true"><?php esc_html_e('Find Out More'); ?></div> | |
</a> | |
<?php | |
} | |
echo "</section>"; | |
} | |
wp_reset_postdata(); | |
}?> | |
<?php endif; ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment