Skip to content

Instantly share code, notes, and snippets.

@jamesgol
Created March 28, 2018 20:40
Show Gist options
  • Save jamesgol/e6b8d029d7b87593ba12e5d814734d3a to your computer and use it in GitHub Desktop.
Save jamesgol/e6b8d029d7b87593ba12e5d814734d3a to your computer and use it in GitHub Desktop.
Keep WooCommerce from mentioning backorders unless the item is actually out of stock
add_filter( 'woocommerce_product_backorders_require_notification', 'jmg_backorders_notification', 10, 2 );
function jmg_backorders_notification( $notify, $product = null ) {
if ( $product && 'notify' === $product->get_backorders() && $product->is_in_stock() ) {
return false;
}
return $notify;
}
@jamesgol
Copy link
Author

Here's what I saw when testing:
Allow backorders: “Do not allow”
with quantity 1: “1 in stock”
with quantity 0: “Out of stock”

Allow backorders: “Allow, but notify customer”
with quantity 1: “1 in stock (can be backordered)”
with quantity 0: “Available on backorder”

Allow backorders: “Allow”
with quantity 1: “1 in stock”
with quantity 0:

If a product is actually in stock, it'll only confuse the customer mentioning backorders (with Allow, but notify customer), but with 'Allow' if the product is out of stock and can be backordered there is nothing displayed at all.

@jamesgol
Copy link
Author

This all came about because of this post in the WordPress.org forum https://wordpress.org/support/topic/available-on-backorder-2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment