Created
December 6, 2018 14:19
-
-
Save WillBrubaker/17d3b0407d1ae3dec77633f3b2c113d8 to your computer and use it in GitHub Desktop.
Remove add to cart button from products that do not have stock
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
//not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/ | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'handsome_bearded_guy_maybe_remove_add_to_cart_button' ); | |
function handsome_bearded_guy_maybe_remove_add_to_cart_button( $html ) { | |
global $product; | |
if ( 'simple' === $product->get_type() && ! $product->get_stock_quantity() ) { | |
return null; | |
} | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My only guess would be that the parent product may actually be returning something that evaluates to
true
from get_stock_quantity while it is the variation that is out of stock.might want to enable
WP_DEBUG
and add some logging statements to see what's what.