Hide product prices when out of stock

Categories: Wordpress, CMS

Hide the price of WooCommerce products when they are out of stock:

add_filter( "woocommerce_variable_sale_price_html", "theanand_remove_prices", 10, 2 );
add_filter( "woocommerce_variable_price_html", "theanand_remove_prices", 10, 2 );
add_filter( "woocommerce_get_price_html", "theanand_remove_prices", 10, 2 );

function theanand_remove_prices( $price, $product ) {
    if ( ! $product->is_in_stock()) {
        $price = "";
    }
    return $price;
}

References: https://stackoverflow.com/questions/22897709/woocommerce-hide-prices-when-inventory-is-set-to-0-or-out-of-stock

«
»