Last active
March 9, 2019 16:30
-
-
Save lawkwok/d2480679fa3a1b79618dae9e376e1930 to your computer and use it in GitHub Desktop.
WooCommerce - Adds stock status to the dropdown on product pages
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 | |
add_action( 'woocommerce_after_add_to_cart_form', 'dropdown_waitlist_label' ); | |
function dropdown_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); | |
$('#pa_size > option').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 ( false == variation.is_in_stock ) { | |
$(this).text( variation.attributes.attribute_pa_size + '\u00A0\u00A0\u00A0–\u00A0\u00A0\u00A0\u00A0Out of Stock'); | |
} | |
if ( variation.min_qty == 1 && variation.max_qty == 1 ) { | |
$(this).text( variation.attributes.attribute_pa_size + '\u00A0\u00A0\u00A0–\u00A0\u00A0\u00A0\u00A01 left in stock' ); | |
} | |
} | |
} | |
}); | |
}); | |
</script>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment