I know I can modify the query to show only the on sale products in the loop like this
add_action('woocommerce_product_query','show_only_on_sale_products');
function show_only_on_sale_products( $q )
{
$product_ids_on_sale = wc_get_product_ids_on_sale();
$q->set( 'post__in', $product_ids_on_sale );
}
How can I make a button where I call this? So I can toggle with it.
PS: I know I can use a shortcode for it but I don't like this solution:
[products limit="4" orderby="popularity" class="quick-sale" on_sale="true" ]