Created
March 10, 2017 20:56
-
-
Save lawkwok/c0ba8696df633731ca0abf12fc640248 to your computer and use it in GitHub Desktop.
Adds .outofstock class to WooCommerce variation input tag
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
add_action( 'woocommerce_after_add_to_cart_form', 'radio_waitlist_label' ); | |
function radio_waitlist_label() { | |
echo " | |
<script> | |
jQuery(document).ready(function($) { | |
var variation_data = $('form.variations_form').attr('data-product_variations'); | |
var variation_data = JSON.parse(variation_data); | |
$('.variations td.value div input').each(function() { | |
for (var i = 0; i < variation_data.length; i++) { | |
var variation = variation_data[i]; | |
if ($(this).val() == variation.attributes.attribute_pa_size) { | |
if ( variation.is_in_stock == false ) { | |
$(this).addClass('outofstock'); | |
} | |
} | |
} | |
}); | |
}); | |
</script>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works with this plugin https://en-ca.wordpress.org/plugins/wc-variations-radio-buttons/
Just style the labels after the .outofstock class. E.g.