Answer the question
In order to leave comments, you need to log in
Products without a price or with a price of 0 at the end of the list?
I have a shop on wordpress + wookomers theme storefront.
How to make products without a price or with a price of 0 shown at the end of the list of products and excluded from sorting?
These codes don't work.
add_filter('posts_clauses', 'order_by_stock_status', 50, 2);
function order_by_stock_status($posts_clauses) {
global $wpdb;
if (!is_admin() && is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
$posts_clauses['orderby'] = "price_query.price > 0 DESC, " . $posts_clauses['orderby'];
}
return $posts_clauses;
}
add_filter('posts_clauses', 'order_by_no_price', 50, 2);
function order_by_no_price($posts_clauses) {
global $wpdb;
if (!is_admin() && is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
if($posts_clauses['join']!=' LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID = wc_product_meta_lookup.product_id '){
$posts_clauses['join'] = $posts_clauses['join'] . " LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID = wc_product_meta_lookup.product_id ";
}
$posts_clauses['orderby'] = "wc_product_meta_lookup.min_price > 0 DESC, " . $posts_clauses['orderby'];
}
return $posts_clauses;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question