Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Last active November 24, 2016 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/248a32e35747f6814cb3 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/248a32e35747f6814cb3 to your computer and use it in GitHub Desktop.
Shows out of stock message when a variable product has all variations out of stock
<?php
//Shows out of stock message when a variable product has all variations out of stock
add_filter('wp_footer', function(){
if(is_product()){
global $product;
if($product->is_type('variable')){
if(!$product->is_in_stock()){
?>
<script>
jQuery(window).load(function(){
var variations = jQuery('.variations_form.cart').data('product_variations');
var $form = jQuery('.variations_form.cart');
var variation = variations[0];
$form.find( 'input[name="variation_id"], input.variation_id' )
.val( variation.variation_id )
.change();
$form.trigger( 'found_variation', [ variation ] );
});
</script>
<?php
}
}
}
},10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment