Skip to content

Instantly share code, notes, and snippets.

@coder618
Created April 14, 2021 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coder618/2cd4ad61d7310e30f087f2ebd288eb72 to your computer and use it in GitHub Desktop.
Save coder618/2cd4ad61d7310e30f087f2ebd288eb72 to your computer and use it in GitHub Desktop.
woocommerce out of stock check
$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