我試圖通過短代碼在自定義頁面上顯示產品的價格。如何使用正確逗號在ID中顯示Woocommerce產品價格?
我發現這個線程:How to display Woocommerce product price by ID number on a custom page?
使用此代碼:
function so_30165014_price_shortcode_callback($atts) {
$atts = shortcode_atts(array(
'id' => null,
), $atts, 'bartag');
$html = '';
if(intval($atts['id']) > 0 && function_exists('wc_get_product')){
$_product = wc_get_product($atts['id']);
$html = "price = " . $_product->get_price();
}
return $html;
}
add_shortcode('woocommerce_price', 'so_30165014_price_shortcode_callback');
簡碼:[woocommerce_price id="99"]
我實現的代碼,並得到它現在的工作的唯一的事是價格沒有正確顯示,它沒有註冊逗號。
比如我有當應顯示爲$1,371.43
$13564.34
當它應該$1371.43
顯示爲$13,564.34
它也做同樣的價格
我試圖植入'number_format' ,但沒有得到運氣。 我將'$ html'傳遞給'$ english_format_number = number_format($ html);' 這個數字仍然提醒了同樣的事情。 – Angel
這樣做:'$ html =「price =」。 number_format($ _ product-> get_price(),2);' – JustRayz
是的,我做了類似的事情。謝謝! – Angel