cbdesign
cbdesign

Reputation: 69

WooCommerce Hide Prices When Inventory is set to '0' or 'out of stock'

I know I can use the css property 'visibility:hidden', to hide the prices on the product listing page (I have it assigned to a specific page id, only on the sold items page.

But on the individual product page is there a piece of PHP I can use that says something like "If item is out of stock/quantity is set to 0, then hide price"?

Main sold out product listing:
http://www.montagemodern.com/sold

Individual Out of stock product page example:
http://www.montagewestport.com/product/pair-of-glass-bubble-lamps/

Upvotes: 1

Views: 3171

Answers (1)

Pbinder
Pbinder

Reputation: 470

Try this:

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

http://wwweb.jextensions.com/theanand.com/blog%252Fhide-price-out-of-stock-woocommerce%252F

Upvotes: 2

Related Questions