Created
April 14, 2021 13:32
-
-
Save coder618/2cd4ad61d7310e30f087f2ebd288eb72 to your computer and use it in GitHub Desktop.
woocommerce out of stock check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$has_stock = false; | |
// echo $product->get_type(); | |
if( $product->get_type() == 'variable' ){ | |
$available_variations = $product->get_available_variations(); | |
foreach( $available_variations as $item ){ | |
if($item['is_in_stock']== true){ | |
$has_stock = true; | |
} | |
} | |
} | |
if( $product->get_type() == 'simple' ){ | |
// if manage stock checked | |
if( $product->managing_stock() ){ | |
if($product->is_in_stock()){ | |
$has_stock = true; | |
} | |
}else{ | |
$has_stock = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment