Created
March 21, 2022 13:14
Add text to Out of Stock variations in WooCommerce - https://aceplugins.com/showing-cart-and-checkout-savings-woocommerce/
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 // 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