Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WooCommerce - Adds stock status to the dropdown on product pages
add_action( 'woocommerce_after_add_to_cart_form', 'dropdown_waitlist_label' );
function dropdown_waitlist_label() {
echo "
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' );

This comment has been minimized.

Copy link

arnsek commented Mar 14, 2019

Hey ajmorris,
i was looking for such a long time for somethins like this. I pasted it without the starting <?php but i am not able to get this to work.
What am i doing wrong? Without the starting <?php it doesnt show any errors, but nothing happens as well... :(
Could you help me getting this to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.