Paste the following code in functions.php:
/* Shortcode to display out of stock products */
add_shortcode( 'out_of_stock_products', 'bbloomer_out_of_stock_products_shortcode' );
function bbloomer_out_of_stock_products_shortcode() {
$args = array(
'post_type' => 'product',
'posts_per_page' => -1, /* "-1" to display all products */
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'outofstock',
)
),
'fields' => 'ids',
);
$product_ids = get_posts( $args );
$product_ids = implode( ",", $product_ids );
return do_shortcode("[products ids='$product_ids']");
}
Then, use the following shortcode to display the products:
[out_of_stock_products]
Source: https://www.businessbloomer.com/woocommerce-display-stock-products-shortcode/