At the moment, if an item is out of stock a message appears in the checkout page:
Sorry, we do not have enough "xxx" in stock to fulfil your order (2 available). We apologise for any inconvenience caused.
Hence If that message appears, then I want to disable the "Proceed to checkout" button on the page by simply removing it.
If it that message doesn’t appear, then display the "Proceed to checkout" button.
I’ll obviously create an IF statement so that if it’s true then display if not, don’t display etc.
Here’s my "Proceed to checkout" button code:
<input type="submit" name="cart_submit" class="checkout-button button alt wc-forward" style="text-transform: capitalize;" value="<?php esc_html_e( 'Proceed to checkout', 'woocommerce' ); ?>" />
So is there a method that I can call in Woocommerce to see if that error message has been called?
I tried scanning the entire webpage for that message and if true, execute xyz but that didn’t work (could be sessions).
Any help would greatly be appreciated.
2
Answers
Woocommerce has a special feature of having product value using global $product.
you can access your product stock quantity using the following code.
Based on
WC_Cart
check_cart_item_stock()
method source code, that displays the error code of your question, The first function will check cart items stock as a conditional function returning true if everything is all right or false if an error has been displayed mentioning that there is a stock issue on cart items.The second function will display a disabled greyed "Place Order" button if there is a stock issue on cart items.
Disabled greyed "Place order" button on checkout page
Code goes in function.php file of your active child theme (or active theme). Tested and works.
If you want to remove the checkout "Place Order" button instead replace:
with:
Related: Customizing checkout "Place Order" button output html