这个问题在这里已有答案:
我有这个产品循环的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而不是on_sale而没有错误 .
1 回答
您可以检查商品是否在销售中
文件https://docs.woocommerce.com/wc-apidocs/source-class-WC_Product.html#1461-1482