我需要帮助:)
我想在我的产品页面上发布稍后付款的消息。例如,我有一个价格为 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();
}
但我不知道如何在该代码中添加公式,并且该代码不显示货币符号。请帮我在该代码中添加一个公式,并显示货币符号($)。
如果有任何帮助,我将非常感激:)
我认为这个案子已经解决了,我会回答也许有人会需要这样的东西......
这是我的修改代码以适合我的情况
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!