Created
August 31, 2012 08:18
-
-
Save ChromeOrange/3550178 to your computer and use it in GitHub Desktop.
Sold Out Shortcode
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 | |
| 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