Last active
August 29, 2015 14:11
-
-
Save daltonrooney/6485de14ba512be527e0 to your computer and use it in GitHub Desktop.
Quick list of wholesale products for Woocommerce Wholesale Ordering plugin
This file contains 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 | |
function wholesale_product_list() { | |
$args = array( | |
'post_type' => 'product', | |
'meta_query' => array( | |
array( | |
'key' => '_wholesale_price', | |
'compare' => '!=', | |
'value' => 0, | |
), | |
), | |
'fields' => 'ids' | |
); | |
$wholesale_products = new WP_Query($args); | |
$posts = $wholesale_products->posts; | |
if ( count($posts) > 0 ) : ?> | |
<table class="shop_table"> | |
<thead> | |
<tr> | |
<th class="product-thumbnail"> </th> | |
<th class="product-name">Product</th> | |
<th class="product-price">Price</th> | |
<th class="product-quantity">Qty.</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ( $posts as $post ) : | |
$product_data = get_post( $post ); | |
$product = wc_setup_product_data( $product_data ); | |
if ( ! $product ) return ''; ?> | |
<tr> | |
<td class="product-thumbnail"> | |
<?php if ( has_post_thumbnail($post) ) : ?> | |
<?php echo get_the_post_thumbnail( $post, 'thumb' ); ?> | |
<?php else : ?> | |
| |
<?php endif;?> | |
</td> | |
<td class="product-name"><a href="<?php echo get_permalink($post);?>"><?php echo get_the_title($post);?></a> | |
<?php if ( get_field('wholesale_notes', $post)) : ?> | |
<br /><span><?php the_field('wholesale_notes', $post);?></span> | |
<?php endif;?> | |
</td> | |
<td class="product-price"><?php echo $product->get_price_html(); ?></td> | |
<td class="product-quantity"><?php woocommerce_template_single_add_to_cart();?></td> | |
</tr> | |
<?php endforeach;?> | |
</tbody> | |
</table> | |
<?php else: ?> | |
<p>There are no wholesale products to display.</p> | |
<?php endif;?> | |
<?php endif;?> | |
<?php wp_reset_query(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment