【发布时间】:2021-02-25 08:59:48
【问题描述】:
我正在使用此代码显示 woocommerce 产品价格
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'] );
$number = number_format($_product->get_price(), 0, '.', ',');
$html = "$" . $number;
}
return $html;
}
add_shortcode( 'woocommerce_price', 'so_30165014_price_shortcode_callback' );
和简码:
[woocommerce_price id="99"]
我想编辑此代码,如果价格等于零而不是零,则显示自定义消息,例如“不可用”。
【问题讨论】:
标签: php wordpress woocommerce shortcode price