"woocommerce show out of stock products last" Code Answer's
You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "woocommerce show out of stock products last" answered properly. Developers are finding an appropriate answer about woocommerce show out of stock products last related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like woocommerce show out of stock products last. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on woocommerce show out of stock products last.
woocommerce show out of stock products last
/**
* Sorting out of stock WooCommerce products - Order product collections by stock status, in-stock products first.
*/
class iWC_Orderby_Stock_Status
{
public function __construct()
{
// Check if WooCommerce is active
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;
// only change query on WooCommerce loops
if (is_woocommerce() && (is_shop() || 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;
/**
* END - Order product collections by stock status, instock products first.
*/
Source: wpdoityourself.com
All those coders who are working on the TypeScript based application and are stuck on woocommerce show out of stock products last can get a collection of related answers to their query. Programmers need to enter their query on woocommerce show out of stock products last related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about woocommerce show out of stock products last for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of woocommerce show out of stock products last while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "woocommerce show out of stock products last". Visit this developer's friendly online web community, CodeProZone, and get your queries like woocommerce show out of stock products last resolved professionally and stay updated to the latest TypeScript updates.