Skip to content

Instantly share code, notes, and snippets.

@coder618
Created April 14, 2021 13:32
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