1
votes

I have a single woocommerce product page where only availability "Out of Stock" message is shown. How can I show a formatted price with currency below that text?

I think I need to insert the following

<p class="price"><span class="woocommerce-Price-amount amount">(PRODUCT PRICE) &nbsp;<span class="woocommerce-Price-currencySymbol">€</span></span></p>

but I dont know how

This is happening to all simple products. As settings, stock management is disabled. I don't know why price is not displayed. I tried to disable some plugins maybe related to that. Like wooocommerce add ons, or discontinued products plugins. I use wp-rocket. The link of a product maybe help you

https://bestfamily.gr/product/steelseries-headset-arctis-pro-wireless-bt/

1

1 Answers

3
votes

You should be able to use something like

<?php
global $product;
$price = $product->get_price();

<p class="price"><span class="woocommerce-Price-amount amount"><?php echo $price; ?> &nbsp;<span class="woocommerce-Price-currencySymbol">€</span></span></p>

You would have to put that in a custom template. If you aren't using one then you could display it below the "add to cart" button using a hook, but as far as I know there isn't any kind of "after stock status" hook.

add_action( 'woocommerce_after_add_to_cart_button', 'add_price_below_button' );
function add_price_below_button() {
    global $product;
    $price = $product->get_price();

    echo '<p class="price"><span class="woocommerce-Price-amount amount">' . $price . ' &nbsp;<span class="woocommerce-Price-currencySymbol">€</span></span></p>';
}

If you only want to display the price if the product is out of stock:

add_action( 'woocommerce_after_add_to_cart_button', 'add_price_below_button' );
function add_price_below_button() {
    global $product;

    if ( $product->get_stock_quantity() <= 0 ) {

        $price = $product->get_price();

        echo '<p class="price"><span class="woocommerce-Price-amount amount">' . $price . ' &nbsp;<span class="woocommerce-Price-currencySymbol">€</span></span></p>';

    }
}

Also as a side note, if Euros is your default currency then you should be able to use get_woocommerce_currency_symbol() to display it.