/*
Theme Name: OceanWP Child Theme
Theme URI: https://oceanwp.org/
Description: OceanWP WordPress theme. Sample child theme.
Author: OceanWP
Author URI: https://oceanwp.org/
Template: oceanwp
Version: 1.0
*/

/* Parent stylesheet should be loaded from functions.php not using @import */

/**
 * @snippet       Display Out of Stock Products via Shortcode - WooCommerce
 */
   
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,
      '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']");
 
}

/**
 * To exclude "Hide of stock Items" from a specific page, adjust page ID number
 */


add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'hide_out_of_stock_exception_page' );
 
function hide_out_of_stock_exception_page( $hide ) {
   if ( is_page( 7506 ) ) {
      $hide = 'no';
   }  
   return $hide;
}

