在简短描述产品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.
For example: "buying this product you get 50 points."
In this example, he earns 50 points because he is in a product that costs $ 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.
Could someone tell me how to do this?
我正在尝试在WooCommerce产品的排序描述中创建一个自动文本,并将产品的价格放入 此消息。 p>
例如:“购买此产品可获得50分。” em> strong> p>
这是我正在使用的代码: p>
我把这个代码放在functions.php中,但它只显示文本,我也不能把产品的价格。 p>
有人能告诉我怎么做吗? p>
div>
add_action('woocommerce_single_product_summary',function(){
echo'购买此产品获得X点';
},25);
code> pre>
Woocommerce has a function just for that. 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();
and just have to declare 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)