-
-
Save akshuvo/03290b58216f504bf596a790a06e2850 to your computer and use it in GitHub Desktop.
Sort product by popularity with price greater than zero
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
add_action( 'woocommerce_product_query', function( $qeury ) { | |
if ( empty( $qeury->query_vars['orderby'] ) || 'popularity' !== $qeury->query_vars['orderby'] ) { | |
return; | |
} | |
add_filter( 'posts_clauses', function( $args ) { | |
$args['orderby'] = ' CASE wc_product_meta_lookup.min_price WHEN 0 THEN 1 | |
ELSE -1 | |
END ASC, wc_product_meta_lookup.total_sales DESC, wc_product_meta_lookup.product_id DESC | |
'; | |
return $args; | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment