简体   繁体   English

在简短描述产品WooCommerce中显示带有价格的自定义文本

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

I am trying to create an automatic text in the sort description of the WooCommerce products and put the price of the product in this message. 我正在尝试在WooCommerce产品的排序描述中创建自动文本,并将产品价格放入此消息中。

For example: "buying this product you get 50 points." 例如:“购买此产品可获得50分。”

In this example, he earns 50 points because he is in a product that costs $ 50 在此示例中,他获得50点积分,因为他使用的产品价格为50美元

Here is the code I am using: 这是我正在使用的代码:

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

I put this code in the functions.php, but it only shows the text, I could not put the price of the product too. 我把这段代码放在functions.php中,但是它只显示文本,我也不能给出产品的价格。

Could someone tell me how to do this? 有人可以告诉我该怎么做吗?

Woocommerce has a function just for that. Woocommerce为此具有功能。 You just need to declare it. 您只需要声明它。 The function is get_price_html() will return the price with the currency format, if you want it without those you can just use the $product->get_price(); 函数是get_price_html()将以货币格式返回价格,如果您不想要这些价格,则可以使用$product->get_price(); and just have to declare global $product; 并且只需要声明global $product; before using it. 在使用它之前。 Here is the code i used. 这是我使用的代码。

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

This is how it gets displayed in my theme (in your theme will be different) 它是如何显示在我的主题中的(您的主题将有所不同) 在此处输入图片说明

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

相关问题 在Woocommerce中的产品简短描述后显示自定义字段值 - Displaying custom field values after product short description in Woocommerce 自定义简码显示 WooCommerce 产品价格:显示零价格文本 - Custom Shortcode displaying WooCommerce product price: Display a text for zero price 避免在 Woocommerce 产品变化描述上出现简短描述附加文本 - Avoid short description additional text to appear on Woocommerce product variations description WooCommerce | 在简短描述的末尾添加自定义文本 - WooCommerce | Add custom text at the end of the short description Woocommerce产品价格乘以短代码显示结果 - Multiplying Woocommerce product price and displaying the result with short code woocommerce 产品摘录说明(短) - woocommerce product excerpt description (short) 删除 Woocommerce 产品简短说明 - Remove Woocommerce Product Short Description 在Woocommerce产品简短说明中替换动态自定义标签 - Replace dynamically custom tags in Woocommerce product short description 在 Woocommerce 单个产品页面的简短描述下显示自定义字段 - Display a custom field under short description in Woocommerce single product pages WooCommerce删除我添加到产品简短描述的自定义jQuery代码 - WooCommerce delete custom jQuery codes I add to Product Short Description
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM