Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shameemreza/d81a1c95aa7d91dcbc53cd960a92e8a1 to your computer and use it in GitHub Desktop.
Save shameemreza/d81a1c95aa7d91dcbc53cd960a92e8a1 to your computer and use it in GitHub Desktop.
Set order status to processing for a single virtual product in 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment