Auto Complete Ticket Order
Last Updated: December 30, 2020
Below code can be added to functions.php or inside a plugin code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
add_filter( 'woocommerce_payment_complete_order_status', 'auto_complete_virtual_orders', 10, 3 ); function auto_complete_virtual_orders( $payment_complete_status, $order_id, $order ) { $current_status = $order->get_status(); // only change status if it is coming from these $allowed_current_statuses = array( 'on-hold', 'pending', 'failed' ); if ( 'processing' === $payment_complete_status && in_array( $current_status, $allowed_current_statuses ) ) { $order_items = $order->get_items(); // Create an array of products in the order $order_products = array_filter( array_map( function( $item ) { // Get associated product for each line item return $item->get_product(); }, $order_items ), function( $product ) { // Remove non-products return !! $product; } ); if( count( $order_products > 0 ) ) { // check if product is a virtual product $is_virtual_order = array_reduce( $order_products, function( $virtual_order_so_far, $product ) { return $virtual_order_so_far && $product->is_virtual(); }, true ); if ( $is_virtual_order ) { $payment_complete_status = 'completed'; } } } return $payment_complete_status; } |
Did this article help you? If not, send us a ticket via helpdesk
Event Tickets Addon Buy Now
Similar Articles
Auto Complete Ticket OrderAuto re-stocking refunded, cancelled or failed ordersChangelog for Event TicketsCODE: How to send Emails as BccHow to add additional data to confirmation emailHow to add additional fields at checkoutHow to add additional fields to download attendees CSV fileHow to customize ticket email templateHow to manage capacity separately for repeat eventsHow to set up Event TicketsHow to set up variable prices for TicketsHow To Switch From WooCommerce Blocks to Shortcode-Based Cart & Checkout Pages