简体   繁体   English

如何在 Woocommerce 缺货产品文本下方添加单个产品的 Woocommerce 产品价格

[英]How can I add below of Woocommerce out of stock product text the Woocommerce product price on a single product

I have a single woocommerce product page where only availability "Out of Stock" message is shown.我有一个 woocommerce 产品页面,其中仅显示可用性“缺货”消息。 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.像 wooocommerce 附加组件或已停产的产品插件。 I use wp-rocket.我使用 wp 火箭。 The link of a product maybe help you产品的链接可能对您有帮助

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

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.另外作为旁注,如果欧元是您的默认货币,那么您应该能够使用get_woocommerce_currency_symbol()来显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM