【问题标题】:How to calculated price in woocommerce如何在woocommerce中计算价格
【发布时间】:2022-08-14 08:19:14
【问题描述】:
我需要帮助:)
我想在我的产品页面上发一条 paylater 消息。例如,我有一个售价 55 美元的产品,我想在它下面输入“向我们支付 4 次 13.75 美元的免息付款”消息,其中 13.75 美元是自动计算的。
我已经找到了代码(简码),因为我想要简码形式的输出。
add_shortcode( \'product_price\', \'display_product_price\' );
function display_product_price( $atts ){
$atts = shortcode_atts( array(
\'id\' => get_the_id(),
), $atts, \'product_price\' );
global $product;
if ( ! is_a( $product, \'WC_Product\') )
$product = wc_get_product($atts[\'id\']);
return $product->get_price();
}
但我不知道如何在该代码中添加公式,并且该代码不显示货币符号。请帮我在该代码中添加一个公式,并调出货币符号($)。
我将非常感谢任何帮助:)
标签:
woocommerce
hook-woocommerce
shortcode
price
【解决方案1】:
我认为这个案子已经解决了,我会回答也许有人会需要这样的东西......
我从他对this question 的回答中找到了这个人的代码praveen。
这是我的案例的修改代码
add_shortcode( 'price_calculated', 'display_price_calculated' );
function display_price_calculated( $atts ){ //create shortcode
global $product;
$id = $product->get_id(); //get current product id
$product = wc_get_product( $id );
$a=$product->get_price(); //get current product price
$b = 4; //because I want my price to be divided in 4
$total = $a/$b; //calculated formula
return get_woocommerce_currency_symbol().$total; //Show the price result, and add a currency symbol before price result
}
现在我只需要添加这个短代码 [price_calculated]
在我的页面上
就是这样,感谢堆栈 StackOverflow!