Created
February 11, 2020 15:14
-
-
Save manchumahara/2afebd0d14790e77e1c93f74e7f5ab71 to your computer and use it in GitHub Desktop.
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_filter( 'woocommerce_shortcode_products_query', | |
function ( $query_args, $attributes, $type ) { | |
if ( $type == 'best_selling_products' ) { | |
unset( $query_args['meta_key'] ); | |
unset( $query_args['meta_query'] ); | |
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; | |
} ); | |
} | |
return $query_args; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment