Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Last active March 8, 2018 22:55
Show Gist options
  • Save WillBrubaker/0ffdc0aed0c574b6c3a5 to your computer and use it in GitHub Desktop.
Save WillBrubaker/0ffdc0aed0c574b6c3a5 to your computer and use it in GitHub Desktop.
Filters the default WooCommerce product category shortcode to only include items on sale
add_filter( 'woocommerce_shortcode_products_query', 'wooninja_only_sale_items', 10, 2 );
function wooninja_only_sale_items( $args, $atts ) {
if ( $atts['category'] ) {
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args['post__in'] = array_merge( array( 0 ), $product_ids_on_sale );
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment