簡體   English   中英

在簡短描述產品WooCommerce中顯示帶有價格的自定義文本

[英]Displaying custom text with price in short description product WooCommerce

我正在嘗試在WooCommerce產品的排序描述中創建自動文本,並將產品價格放入此消息中。

例如:“購買此產品可獲得50分。”

在此示例中,他獲得50點積分,因為他使用的產品價格為50美元

這是我正在使用的代碼:

add_action( 'woocommerce_single_product_summary', function() {
   echo 'Buying this product you get X points';
}, 25 );

我把這段代碼放在functions.php中,但是它只顯示文本,我也不能給出產品的價格。

有人可以告訴我該怎么做嗎?

Woocommerce為此具有功能。 您只需要聲明它。 函數是get_price_html()將以貨幣格式返回價格,如果您不想要這些價格,則可以使用$product->get_price(); 並且只需要聲明global $product; 在使用它之前。 這是我使用的代碼。

function PricePoints(){
  global $product;
  echo 'Buying this product you get '.$product->get_price().' points';
}
add_action( 'woocommerce_single_product_summary','PricePoints',25);

它是如何顯示在我的主題中的(您的主題將有所不同) 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM