Created
March 22, 2013 11:45
-
-
Save alexpani/5220682 to your computer and use it in GitHub Desktop.
Aggiunge shortcode per prodotti in offerta in Woocommerce
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 | |
/* | |
Plugin Name: Woocommerce Sale Products Shortcode | |
Version: 0.1 | |
* Usage: [sale_products] | |
* Options & Default | |
per_page=12 | |
columns=4 | |
orderby=title | |
order=asc | |
*/ | |
/** | |
* List all products on sale | |
* | |
* @access public | |
* @param array $atts | |
* @return string | |
*/ | |
function woocommerce_sale_products( $atts ){ | |
global $woocommerce_loop; | |
extract( shortcode_atts( array( | |
'per_page' => '12', | |
'columns' => '4', | |
'orderby' => 'title', | |
'order' => 'asc' | |
), $atts ) ); | |
$args = array( | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'ignore_sticky_posts' => 1, | |
'orderby' => $orderby, | |
'order' => $order, | |
'posts_per_page' => $per_page, | |
'meta_query' => array( | |
array( | |
'key' => '_visibility', | |
'value' => array('catalog', 'visible'), | |
'compare' => 'IN' | |
), | |
array( | |
'key' => '_sale_price', | |
'value' => 0, | |
'compare' => '>', | |
'type' => 'NUMERIC' | |
) | |
) | |
); | |
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(); | |
} | |
add_shortcode('sale_products', 'woocommerce_sale_products'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment