Change "Add to cart" button text on archives for out of stock products in WooCommerce with PHP

add_action( 'woocommerce_product_add_to_cart_text', 'wpcb_add_to_cart_text_on_loop_out_of_stock_products', PHP_INT_MAX, 2 );
if ( ! function_exists( 'wpcb_add_to_cart_text_on_loop_out_of_stock_products' ) ) {
    /**
     * wpcb_add_to_cart_text_on_loop_out_of_stock_products.
     */
    function wpcb_add_to_cart_text_on_loop_out_of_stock_products( $text, $product ) {
        return ( ! $product->is_in_stock() ? 'Out of stock' : $text );
    }
}

You can add this snippet to your (child) theme's functions.php file.

No comments yet.

Leave a Reply