mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/59891062/prevent-admin-from-making-orders-for-out-of-stock-products-in-woocommerce
7 lines
402 B
Text
7 lines
402 B
Text
add_filter( 'woocommerce_ajax_add_order_item_validation', 'wc_woocommerce_ajax_add_order_item_validation', 10, 2 );
|
|
function wc_woocommerce_ajax_add_order_item_validation( $validation_error, $product ) {
|
|
if ( $validation_error && !$product->is_in_stock() ) {
|
|
$validation_error->add( 'product-out-of-stock', __('Product Out of Stock', 'woocommerce') );
|
|
}
|
|
return $validation_error;
|
|
}
|