Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Last active February 5, 2025 15:28
Show Gist options
  • Save andrasguseo/52a6a2a2ba94882d9fe1ea031ec05149 to your computer and use it in GitHub Desktop.
Save andrasguseo/52a6a2a2ba94882d9fe1ea031ec05149 to your computer and use it in GitHub Desktop.
ETP + Woo > Autocomplete some orders
<?php
/**
* Set WooCommerce orders for Ticket products to 'completed' status automatically based on certain criteria.
*
* You can further tweak the behavior by adjusting the snippet:
* - based on order status: line 29
* - based on payment gateway: line 36
*/
add_action( 'woocommerce_thankyou', function ( $order_id ) {
// Bail if there is no order.
if ( ! $order_id ) {
return;
}
// Bail if there's no Event Tickets Plus.
if ( ! class_exists( 'Tribe__Tickets_Plus__Main' ) ) {
return;
}
// Get the order data.
$order = wc_get_order( $order_id );
/**
* Don't set the order status to 'completed' if the order is not set to 'processing' status.
*
* Note: For some WooCommerce payment gateways (e.g. cheque), the order status is set to 'on-hold', for some to 'processing'.
*
*/
if ( $order->get_status() != 'processing' ) {
return;
}
/**
* Don't set the order status to 'completed' if the 'cheque' payment gateway has been used.
*/
if ( $order->get_payment_method() == 'cheque' ) {
return;
}
$all_virtual = true;
$all_tickets = true;
foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$product_id = $product->get_id();
if ( ! $product->is_virtual() ) {
$all_virtual = false;
break;
}
if ( ! function_exists( 'tribe_events_product_is_ticket' ) || ! tribe_events_product_is_ticket( $product_id ) ) {
$all_tickets = false;
break;
}
}
if ( $all_virtual && $all_tickets ) {
$order->update_status( 'completed' );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment