Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Woocommerce "out of stock" items price

I'd like to display my out of stock items, but without price in WooCommerce. Is there any easy way to hide price of "out of stock" items?

Thanks!

like image 694
user3280580 Avatar asked Oct 21 '25 13:10

user3280580


2 Answers

Adding these to the CSS worked for me. The first one removes the price from the out of stock item's page and the second removes the price from the out of stock item in search results.

.outofstock .price{display:none}

.outofstock .amount{display:none}

like image 149
ForTheSportsFan.com Avatar answered Oct 23 '25 06:10

ForTheSportsFan.com


Create a file price.php in /your-theme/woocommerce/single-product/ folder. Paste the following code.

$pricelabel = ""; - will be the variable that will display instead of the price if the stock quantity is 0.

If you use $pricelabel = ""; - this will remove the price. You can try $pricelabel = "SOLD OUT!"; or whatever message you want to display if you want.

I actually wrote this code to display a text message instead of a particular price. I just changed it to check stock quantity instead of price.

<?php
/**
 * Single Product Price, including microdata for SEO
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $post, $product;
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">

    <p class="price"> <?php 
        $stockamount = $product->get_stock_quantity();
        $price = $product->get_price_html();
        $pricelabel = "";
        if($stockamount == 0)
        {
            echo $pricelabel;
        }
        else
        {
            echo $price;            
        }; 
    ?>
    </p>

    <meta itemprop="price" content="<?php echo $product->get_price(); ?>" />
    <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" />
    <link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />

</div>
like image 42
lartan Avatar answered Oct 23 '25 04:10

lartan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!