Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Display out of stock products last (even after sort) - Woocommerce

add_filter('posts_clauses', 'order_by_stock_status',999);
function order_by_stock_status($posts_clauses) {
    global $wpdb;
    // only change query on WooCommerce loops
    if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
        $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
        $posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
        $posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
    }
    return $posts_clauses;
}
Comment

PREVIOUS NEXT
Code Example
Php :: foreach loog in php 
Php :: search highlighting 
Php :: eager loading in hasmany belongsto relationship 
Php :: woocommerce affiliate product link image to external link 
Php :: get average of sql column php 
Php :: php include inside function global 
Php :: php strom key 2 
Php :: http://www.endmemo.com/program/R/vector.php 
Php :: php isset and test 
Php :: php git pull webhook 
Php :: list bulan php 
Php :: yoast seo alternative for laravel 
Php :: get pivot id laravel 
Php :: : in php 
Php :: envoyer mail php depuis localhost 
Php :: php 5.6 xampp 
Php :: $score = $score + $bonus Score; return $score; php 
Php :: php generate html attributes from array 
Php :: section laravel append 
Php :: how can we export larage data from table in laravel 8 
Php :: php cut after first sentence 
Php :: Multiple trait declaration in PHP 
Php :: wc php order view order link 
Php :: laravel rename file if exists 
Php :: codeigniter sanitize array in php 
Php :: dot after each character php 
Php :: livewire layout error 
Php :: spatie sluggable not working 
Php :: Laravel Cache store [none] is not defined. 
Php :: php array_diff vs array_diff_assoc 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =