Skip to content

Instantly share code, notes, and snippets.

@dkvadratu
Created February 8, 2021 07:41
Show Gist options
  • Save dkvadratu/cae07971c38b89c581496b426d0ecdd9 to your computer and use it in GitHub Desktop.
Save dkvadratu/cae07971c38b89c581496b426d0ecdd9 to your computer and use it in GitHub Desktop.
{WC} query products on sale trough GET
<?php
add_filter('loop_shop_post_in', 'dk_filter_sale_products', 10);
add_filter('woocommerce_widget_get_current_page_url', 'dk_filter_links_with_sale', 10, 2);
function dk_filter_sale_products($array) {
if(isset($_GET['akcija']) && $_GET['akcija']){
$product_ids_on_sale = wc_get_product_ids_on_sale();
$array = array_merge($array, $product_ids_on_sale);
}
return $array;
}
function dk_filter_links_with_sale ($link, $widget) {
if(isset($_GET['akcija']) && $_GET['akcija']) {
$link = add_query_arg( 'akcija', '1', $link );
}
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment