Created
April 9, 2016 17:45
-
-
Save yratof/0da0060b3d01220d46bd42cc4ef4657e to your computer and use it in GitHub Desktop.
Woocommerce sale items via URL
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 | |
// Display sale items only when searching by /?sale=show | |
add_action('pre_get_posts','sale_items'); | |
function sale_items($query) { | |
if (!is_admin() && ( $query->is_post_type_archive( 'product' ) || $query->is_tax( get_object_taxonomies( 'product' ))) && isset($_GET['sale']) && $_GET['sale'] == 'show' ) { | |
$meta_query = array( | |
array( | |
'key' => '_sale_price', | |
'value' => 0, | |
'compare' => '>', | |
'type' => 'numeric' | |
) | |
); | |
$query->set( 'meta_query' , $meta_query ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment