Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
Forked from ChromeOrange/functions.php
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save ofernandolopes/7569b80e6910501eefa6 to your computer and use it in GitHub Desktop.

Select an option

Save ofernandolopes/7569b80e6910501eefa6 to your computer and use it in GitHub Desktop.
WooCommerce - Sold Out Shortcode
<?php
add_shortcode('soldoutproducts', 'custom_woocommerce_soldout_products');
/**
* Recent Products shortcode with custom styles
**/
function custom_woocommerce_soldout_products( $atts ) {
global $woocommerce_loop;
extract(shortcode_atts(array(
'per_page' => '9999',
'columns' => '4',
'orderby' => 'date',
'order' => 'desc'
), $atts));
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $per_page,
'orderby' => $orderby,
'order' => $order,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'sold-out'
)
)
);
ob_start();
$products = new WP_Query( $args );
$woocommerce_loop['columns'] = $columns;
if ( $products->have_posts() ) : ?>
<ul class="products">
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
</ul>
<?php endif;
wp_reset_query();
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment