Woo : Change “Out of Stock” to SOLD OUT

This is a quality of life improvement for an ecommerce store.

<?php

add_filter( 'woocommerce_product_single_add_to_cart_text', 'dd_custom_single_add_to_cart_text' ); 
function dd_custom_single_add_to_cart_text(){
    global $product;
    if ($product->get_stock_status() !== 'instock'){
        return __( 'SOLD OUT', 'woocommerce' );
    } else {
        return __( 'Add to cart', 'woocommerce' );
    }
}

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You’ll also get DPlugins product updates. No spam, and you can unsubscribe anytime.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You'll also get DPlugins product updates. No spam, and you can unsubscribe anytime.

Click to Copy