![](/img/trans.png)
[英]Order status processing issue on successful payment from Paypal in Woocommerce
[英]Set order status to "Processing" after payment for a single virtual product in WooCommerce
WooCommerce,任何虛擬商品訂單狀態在付款后自動標記為“已完成”。
我需要在付款后將狀態設置為“處理中”。 此行為應僅適用於我指定的單個虛擬產品 ID。
我正在尋找的最接近的解決方案是:
在 WooCommerce 中自動將特定產品的訂單狀態更改為已完成
唯一的問題是它將狀態設置為“已完成”而不是“處理中”,而我需要相反的方式。
function virtual_product_woocommerce_order_status( $order_id ) {
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
$order_items = $order->get_items();
$is_virtual_found = false;
$order_product_ids = array();
$specific_product_id = 1342;
foreach ( $order_items as $item ) {
// Get product id
$product = wc_get_product( $item['product_id'] );
// Add the product IDS to the list
$order_product_ids[] = $item['product_id'];
// Is virtual
$is_virtual = $product->is_virtual();
// Is_downloadable
$is_downloadable = $product->is_downloadable();
// Backorders allowed
$backorders_allowed = $product->backorders_allowed();
if( $is_virtual && $is_downloadable && $backorders_allowed ) {
$is_virtual_found = true;
break;
}
}
// true
if( $is_virtaul_found && in_array($specific_product_id, $order_product_ids) ) {
$order->update_status( 'processing' );
}
}
add_action('woocommerce_thankyou', 'virtual_product_woocommerce_order_status', 10, 1 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.