-
Notifications
You must be signed in to change notification settings - Fork 0
/
jump-back-oostock.php
20 lines (19 loc) · 1023 Bytes
/
jump-back-oostock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
class iWC_Orderby_Stock_Status {
public function __construct() {
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
add_filter('posts_clauses', array($this, 'order_by_stock_status'), 2000);
}
}
public function order_by_stock_status($posts_clauses) {
global $wpdb;
// if you got another taxonomy u wanna use change "if" section like is_tax("product_brand")
if (is_woocommerce() && (is_shop() || is_tax("product_brand") || is_product_taxonomy() || is_product_category() || is_product_tag())) {
$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;
}
}
new iWC_Orderby_Stock_Status;