Woo : Change “Out of Stock” to SOLD OUT

smartsovereign
18 May 2022

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' );
    }
}

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy