<?php
/**
* Separate file
* Add a $is_oos_last variable before the woof shortcode then set it to false after the shortcode
*/
?>
<?php $is_oos_last = true; ?>
<?php echo do_shortcode( '[woof_products per_page="12" columns="3" is_ajax="1"]' ); ?>
<?php $is_oos_last = false; ?>
<?php
/**
* functions.php
* Modify the query to push out of stock at the bottom of the list
*/
add_filter('posts_clauses', 'tbd_order_by_stock_status', 9999);
function tbd_order_by_stock_status($posts_clauses)
{
global $wpdb;
global $is_oos_last;
if ($is_oos_last == 1 || $_GET['is_oos_last'] == 1 || 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'] = " istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
}
return $posts_clauses;
}
add_filter('woof_draw_products_get_args', 'tbd_woof_draw_products_get_args', 9999 );
function tbd_woof_draw_products_get_args( $args ) {
$args['is_oos_last'] = 1;
return $args;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter