Moving Out Of Stock Products To The End Of Pages In The WP-E-Commerce Plugin (WPEC)

Currently when you browse through the products pages on our wp-e-commerce WordPress site, all of the out of stock products show across all the pages.

What we would like to be able to to do, is to move all of the out of stock products to the end of the pages, so that in order to view the out of stock products, you would have to scroll through all the pages, which would be showing the products that are in stock, in order to improve the user experience.

We would like to be able to either come up with a filter to go in functions.php, or change the below code to achieve this:

 `class OrderWpscProducts {

  // flag for when a shop products post query is being created
  private $isProductQuery = false;

  public function __construct() {
  // hooks for altering order of product pages
  add_filter('parse_query', array($this, 'filterProductQueryMark'), 20);
  add_filter('posts_join', array($this, 'filterProductQueryJoins'), 20);
  add_filter('posts_orderby', array($this, 'filterProductQueryOrderBy'), 20);
  }

  /**
  * detect a posts query that should return a list of shop products,
  * and mark it for later filters
  * @param WP_Query $query
  * @return WP_Query
  */
  public function filterProductQueryMark($query) {
  $this->isProductQuery = false;

  if (!is_admin() && (wpsc_is_in_category() || !empty($query->query_vars['wpsc_wine_style']))) {
    $this->isProductQuery = true;
  }
  }

  /**
  * if the posts query is for a list of shop products,
  * then add some tables to the join so that we can sort by category name
  * @param string $joins
  * @return string
  */
  public function filterProductQueryJoins($joins) {
  global $wpdb;

  if ($this->isProductQuery) {
  $joins .= "
  INNER JOIN $wpdb->term_relationships wpsc_cat_rel ON wp_posts.ID = wpsc_cat_rel.object_id
  INNER JOIN $wpdb->term_taxonomy wpsc_cat_tax ON wpsc_cat_tax.term_taxonomy_id =                        wpsc_cat_rel.term_taxonomy_id
  and wpsc_cat_tax.taxonomy = 'wpsc_product_category'
  INNER JOIN $wpdb->terms wpsc_cat ON wpsc_cat.term_id = wpsc_cat_tax.term_id
  "; }

  return $joins;
  }

  /**
  * if the posts query is for a list of shop products, then sort by category name and product title
  * @param string $orderby
  * @return string
  */
  public function filterProductQueryOrderBy($orderby) {
  if ($this->isProductQuery) {
    $orderby = 'wpsc_cat.name ASC, wp_posts.post_title ASC';
  }

  return $orderby;
  }
  }

  // create instance, will be kept alive by hooks
  new OrderWpscProducts(); `

Had a go at trying to create a filter (still new to php, but had a go with the following).

If anyone has any suggestions on how the above code could be changed to move the out of stock products to the end of the pages, or how the below filter could be changed to achieve that, it would be really appreciated:

add_filter('posts_clauses', 'order_by_stock_status');
function order_by_stock_status($posts_clauses) {
global $wpdb;
// only change query on wp-e-commerce loops
if (!is_admin() && (is_productQuery() || is_wpsc_product_category() || is_product_tag() ||          is_wpsc_cat.taxonomy_id())) {
$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;
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật