Skip to content

Instantly share code, notes, and snippets.

@apsolut
Created June 20, 2016 00:29
Show Gist options
  • Save apsolut/516f75a97caf895d89c2ba2def647b81 to your computer and use it in GitHub Desktop.
Save apsolut/516f75a97caf895d89c2ba2def647b81 to your computer and use it in GitHub Desktop.
WOO - Display only outofstock products
<?php
$outofstock_arg = array(
'post_type' => array('product', 'product_variation'), //'product', 'product_variation'
'post_status' => 'publish',
'meta_query' => array(
// https://github.com/woothemes/woocommerce/blob/master/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
array(
'key' => '_stock_status',
'value' => 'outofstock', //instock
'compare' => 'IN'
)
),
'posts_per_page' => 4,
'order' => 'ASC',
'ignore_sticky_posts' => true,
'suppress_filters' => false,
); ?>
<?php
$outofstock_query = new WP_Query( $outofstock_arg );
if ( $outofstock_query->have_posts() ) : ?>
<div class="just-outofstock">
<?php while ( $outofstock_query->have_posts() ) : $outofstock_query->the_post(); ?>
<li <?php post_class(); ?>>
<?php
/**
* woocommerce_before_shop_loop_item hook.
*
* @hooked woocommerce_template_loop_product_link_open - 10
*/
do_action( 'woocommerce_before_shop_loop_item' );
/**
* woocommerce_before_shop_loop_item_title hook.
*
* @hooked woocommerce_show_product_loop_sale_flash - 10
* @hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
/**
* woocommerce_shop_loop_item_title hook.
*
* @hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item_title hook.
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item hook.
*
* @hooked woocommerce_template_loop_product_link_close - 5
* @hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
?>
</li>
<?php endwhile; ?>
</div>
<?php endif; wp_reset_postdata(); ?>
<!-- meta keys
_price =
_stock_status = outofstock
_downloadable = yes
_wpuf_form_id = 43
_edit_lock = 1370858513:1
_edit_last = 1
_visibility = visible
total_sales = 0
_virtual = no
_product_image_gallery =
_regular_price =
_sale_price =
_tax_status =
_tax_class =
_purchase_note =
_featured = no
_weight =
_length =
_width =
_height =
_sku =
_product_attributes = a:1:{s:7:"pa_test";a:6:{s:4:"name";s:7:"pa_test";s:5:"value";s:0:"";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}
_sale_price_dates_from =
_sale_price_dates_to =
_sold_individually =
_stock =
_backorders = no
_manage_stock = no
_file_paths = a:0:{}
_download_limit =
_download_expiry =
linked_item = 0
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment