jQuery(document).on('added_to_cart', function(event, fragments, cart_hash, $button) { // Success: WooCommerce handled it }); jQuery(document).on('wc_cart_button_updated wc_add_to_cart_error', function(event, $button) { // Out of stock or failed: show error, reset button $button.removeClass('loading'); $button.prop('disabled', false); $button.text('Out of Stock'); alert('Sorry, this product is now out of stock and cannot be added to the cart.'); });