在Woocommerce中,我有这个PHP代码输出产品价格和罚款。
但我也需要他也打印价格除以10.我尝试了很多方法而且它不起作用。
下面是代码:
if ($hide_price !== '0') :
$output_price .= '<div class="dhvc-woo-price dhvc-woo-span6">';
$output_price .= $product->get_price_html (); //this is where the price is called
$output_price .= '<p><br>Em até 10x de</p>'; //this is where it should print the price / by 10
$output_price .= '</div>';
endif;
$output .= apply_filters('dhvc_woo_price', $output_price, $product, $display);
我试过$output_price .= $product->get_price_html() / 10;
//它给了我0
还尝试了其他方式,它只是给了我php错误。
感谢任何帮助。
答案 0 :(得分:1)
您需要使用wc_get_price_to_display($product)
而不是$product->get_price_html()
来输出原始数字价格。
wc_get_price_to_display($product)
会关心显示税或非一般选项 ... ($product->get_price()
不是这种情况)
代码:
if ($hide_price !== '0') :
$output_price .= '<div class="dhvc-woo-price dhvc-woo-span6">';
$output_price .= $product->get_price_html (); //this is where the price is called
// Here your correct price divided by 10 and formatted for the output
$price_d10 = wc_price(wc_get_price_to_display($product) / 10);
$output_price .= '<p><br>Em até 10x de '. $price_d10 .'</p>';
$output_price .= '</div>';
endif;
$output .= apply_filters('dhvc_woo_price', $output_price, $product, $display);
经过测试和工作
答案 1 :(得分:0)
也许:
$product->get_price()/10;
或
number_format((float)$product->get_price()/10, 2, '.', '');
有两位小数?