Created
November 8, 2023 10:54
-
-
Save hslaszlo/871d4e93f453b3329b6c15bb8351a159 to your computer and use it in GitHub Desktop.
WooCommerce: check if product is out of stock and doesn't allow backorders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
// source: https://stackoverflow.com/questions/51327748/woocommerce-check-if-product-is-out-of-stock-and-doesnt-allow-backorders | |
*/ | |
add_action('woocommerce_single_product_summary','show_stock_single',5); | |
function show_stock_single() { | |
global $product; | |
$StockQ=$product->get_stock_quantity(); | |
if ($StockQ>=1)//Stock is Available | |
{ | |
echo "<p>Available</p>"; | |
} | |
elseif($StockQ<1)//Product is Out of Stock | |
{ | |
echo "<p>Out of Stock</p>"; | |
if ($product->backorders_allowed())//Product is out of stock AND allow backorders | |
{ | |
echo "<p>Backorder Allowed</p>"; | |
} | |
else//Product is out of stock AND DO NOT allow backorders | |
{ | |
echo "<p>Backorder NOT Allowed</p>"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment