Skip to content

Instantly share code, notes, and snippets.

Add text to Out of Stock variations in WooCommerce - https://aceplugins.com/showing-cart-and-checkout-savings-woocommerce/
<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Add text to out of stock variations.
*
* Related post: https://aceplugins.com/showing-cart-and-checkout-savings-woocommerce/
*/
function ace__add_text_out_of_stock_variations() {
wp_add_inline_script( 'wc-add-to-cart-variation', "
var outOfStockText = ' (out of stock)'
jQuery('.variations_form').on('woocommerce_update_variation_values', function() {
jQuery(this).find('option:disabled').text(function(i, v) {
return v.replace(outOfStockText, '') + ' ' + outOfStockText
})
})
" );
}
add_action( 'wp_enqueue_scripts', 'ace__add_text_out_of_stock_variations' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment