【发布时间】:2021-03-28 17:44:58
【问题描述】:
我成功地在特定类别中运行大规模折扣(假设类别 id 123 中的 -50%)并且在产品网格、产品页面和订单中一切都运行顺利。 (Wordpress 5.7,Woocommerce:5.1.0,尝试了各种大减价插件)
但问题是当我尝试通过我制作的一个小插件在管理页面中打印列表时,我无法获得销售价格
我试过了:
global $woocommerce;
$args = array('post_type'=>'product','post_status'=>'publish','ignore_sticky_posts'=>1);
$query = new WP_Query( $args );
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) : $query->the_post();
global $product;
$product = wc_get_product( get_the_ID() );
echo $product->get_sale_price()."<br>"; //prints empty
echo $product->get_price()."<br>"; //prints the initial price
echo wc_price( wc_get_price_including_tax( $product ) ).'<br>'; //prints the initial price
echo $product->get_variation_sale_price( 'min', true ).'<br>'; //prints the initial price
if ( $product->is_on_sale() ){
echo 'is on sale<br>'; //it never prints so it does not recognise the product as in sale
}
endwhile;
}
为什么没有售价?我怎么才能得到它?大多数产品都有变化。产品页面包含销售运行的类别中所有产品的销售价格。
【问题讨论】:
-
请对以下代码提供一些反馈。
标签: php wordpress woocommerce backend discount