/*
Theme Name: Flatsome Child
Description: This is a child theme for Flatsome Theme
Author: UX Themes
Template: flatsome
Version: 3.0
*/

/*************** ADD CUSTOM CSS HERE.   ***************/
/**
 * @snippet       Cumulative Stock Quantity @ Variable Product
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */
// CALCULATE CUMULATIVE STOCK
 
function bbloomer_cumulative_stock_variations( $product ) {
    if ( $product->get_type() == 'variable' && ! $product->get_manage_stock() ) {
      $cumulative_stock = 0;
        foreach ( $product->get_available_variations() as $key ) {
            $variation = wc_get_product( $key['variation_id'] );
            $cumulative_stock += $variation->get_stock_quantity() ? $variation->get_stock_quantity() : 0;
        }
    }
   return $cumulative_stock;
}
 
// SET VARIABLE PRODUCT STOCK QUANTITY
 
add_filter( 'woocommerce_get_stock_html', 'bbloomer_variable_product_cumulative_stock', 9999, 2 );
 
function bbloomer_variable_product_cumulative_stock( $html, $product ) {
   $availability = $product->get_availability();
   if ( $product->get_type() == 'variable' && empty( $availability['availability'] ) ) {
      ob_start();
      wc_get_template(
         'single-product/stock.php',
         array(
            'product' => $product,
            'class' => bbloomer_cumulative_stock_variations( $product ) > 0 ? 'in-stock' : 'out-of-stock',
            'availability' => sprintf( __( '%s in stock', 'woocommerce' ), bbloomer_cumulative_stock_variations( $product ) ),
         )
      );
      return ob_get_clean();
   }
   return $html;
}
 
// SHOW STOCK @ SINGLE VARIABLE PRODUCT PAGE
 
add_action( 'woocommerce_before_add_to_cart_form', 'bbloomer_stock_for_variable_products' );
 
function bbloomer_stock_for_variable_products() {
   global $product;
   $availability = $product->get_availability();
   if ( $product->get_type() == 'variable' && empty( $availability['availability'] ) ) {
      echo wc_get_stock_html( $product );
   }
}

._df_thumb{
    width:480px;
}
@media only screen and (max-width: 48em) {
/*************** ADD MOBILE ONLY CSS HERE  ***************/


}