我有针对woocommerce的这个产品循环
<?php global
$woocommerce;
$currency = get_woocommerce_currency_symbol();
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale = get_post_meta( get_the_ID(), '_sale_price', true);
$percent = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
$marca = $product->get_attribute( 'marcas' );
?>
<?php echo $percent; ?>
但我想展示这个($百分比)只有产品真的是on_sale才能在同一个列表中列出两种类型的产品,on_sale&amp;没有错误的on_sale。
答案 0 :(得分:1)
您可以检查商品是否在销售中
$is_on_sale = $product->is_on_sale();
if ( $is_on_sale ) {
//display sale percent
...
}else{//product not on sale
//display regular price
...
}
文档https://docs.woocommerce.com/wc-apidocs/source-class-WC_Product.html#1461-1482