我一直在寻找重新计算任何woocommerce订单的最佳方式,其状态为“暂停”状态。如果自下订单以来价格销售或正常价格发生变化。例如:如果我带来29.99的商品,那么我将售价从管理端更改为25.99。如果订单状态为“暂停”,我想在前端和管理端更新任何新订单。
我已经开始编写代码,但是我很难想到最好的方法,或者它是否有效:
add_action('woocommerce_order_status_changed','status_changed_processsing');
function status_changed_processsing( $order_id, $checkout = null ) {
global $woocommerce;
global $product;
$product = new WC_Product();
$order = new WC_Order( $order_id );
if( $order->status == 'on-hold' ){
foreach (products as $product);
global $product;
#1 Get product variations
$product_variations = $product->get_available_variations();
#2 Get one variation id of a product
$variation_product_id = $product_variations [0]['variation_id'];
#3 Create the product object
$variation_product = new WC_Product_Variation( $variation_product_id );
#4 Use the variation product object to get the variation prices
echo $variation_product ->regular_price;
echo $variation_product ->sale_price;
# Single Product
if( $product->is_on_sale() ) {
return $product->get_sale_price();
}else {
return $product->get_regular_price();
}
}
}