Im allowing backorders in my store, but i don't want the stock quantity to be negative.
I tried to fix this using this :
add_action('woocommerce_variation_set_stock', 'avoid_negative_stock', 10, 1);
function avoid_negative_stock( $product ) {
if ( did_action( 'woocommerce_variation_set_stock' ) >= 2 )
return;
if($product->get_stock_quantity() < 0){
$product->set_stock_quantity(0);
$product->save();
}
}
But it doesn't work :/
Can anyone help me up with that ?
Regards