Skip to content

Instantly share code, notes, and snippets.

@musicalbigfoot
Created June 21, 2015 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musicalbigfoot/ce8d86175e05cdf5fb7e to your computer and use it in GitHub Desktop.
Save musicalbigfoot/ce8d86175e05cdf5fb7e to your computer and use it in GitHub Desktop.
Wordpress Woocommerce Product Archive
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'no',
'posts_per_page' => -1,
'order' => 'asc',
);
$products = array();
$products_query = new WP_Query( $args );
if ($products_query->have_posts()) :
while ($products_query->have_posts()) :
$products_query->the_post();
$product = get_product( $products_query->post->ID );
if ($product->id != $featured_product_id) {
$img = wp_get_attachment_image_src( $product->get_image_id(), 'medium' );
$products[] = array(
'title' => $product->post->post_title,
'image' => $img[0],
'permalink' => $product->get_permalink(),
'price' => $product->get_price(),
);
}
endwhile;
endif;
wp_reset_query();
if ( count($products) > 0 ) : ?>
<div class="product-archive row">
<!-- <h2>Accessories</h2> -->
<ul class="product-accessories large-block-grid-3 medium-block-grid-1">
<?php foreach ($products as $product): ?>
<li class="product-item">
<a href="<?php echo $product["permalink"] ?>" class="product-image" style="background-image: url(<?php echo $product["image"] ?>);"></a>
<h3><a href="<?php echo $product["permalink"] ?>"><?php echo $product["title"] ?></a></h3>
<?php if ($product["price"] != ""): ?>
<span class="price">$<?php echo number_format($product["price"], 2) ?></span>
<?php endif ?>
<a href="<?php echo $product["permalink"] ?>" class="button">More Info</a>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment