Last active
December 22, 2017 22:54
-
-
Save NickGreen/961a71c6f422d09b58749b198742e211 to your computer and use it in GitHub Desktop.
Hide products that have no stock, but still allow backorders.
This file contains 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 | |
/* | |
* Use case: Product has 'allow backorders' enabled to allow purchase | |
* of products with stock fewer than 1, but they want them to be purchasable | |
* if direct linked to or added to the cart in other ways. | |
*/ | |
function pp_always_hide_zero_stock( $is_visible, $id ) { | |
$product = wc_get_prodcut( $id ); | |
if ( $product->stock < 1 ) { | |
$is_visible = false; | |
} | |
return $is_visible; | |
} | |
add_filter( 'woocommerce_product_is_visible', 'pp_always_hide_zero_stock', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment