Updated - To detect "out of stock" selected variation and hide add to cart button block, the way is to use jQuery:
add_action( 'wp_footer', 'single_add_to_cart_event_text_replacement' );
function single_add_to_cart_event_text_replacement() {
global $product;
// Only single variable products
if( ! ( is_product() && $product->is_type('variable') ) )
return;
?>
<script type="text/javascript">
jQuery(function($){
var vs = 'table.variations select', vi = 'input.variation_id',
atc = 'woocommerce-variation-add-to-cart', atcd = atc+'-disabled',
atc = '.'+atc;
// 1. On start (With a mandatory light delay)
setTimeout(function(){
if ( 0 < $(vi).val() && $(atc).hasClass(atcd) ) {
$(atc).hide();
}
}, 250);
// 2. On variation change
$('.variations_form').on( 'blur', vs, function(){
if( 0 < $(vi).val() && $(atc).hasClass(atcd) ){
$(atc).hide();
} else {
$(atc).show();
}
});
})
</script>
<?php
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
The CSS way (not convenient)
As the <div>
container get a tag class woocommerce-variation-add-to-cart-disabled
that grey out the add to cart button you could use a CSS rule to hide the entire block the button and the quantity field:
.woocommerce-variation-add-to-cart-disabled { display:none !important; }
But When no variations are selected it will also hide add to cart, so it's not convenient.