Skip to content

Instantly share code, notes, and snippets.

@skyshab
Created July 26, 2021 13:48
Show Gist options
  • Save skyshab/d5474fc238329cb6c8519ada986f2b7e to your computer and use it in GitHub Desktop.
Save skyshab/d5474fc238329cb6c8519ada986f2b7e to your computer and use it in GitHub Desktop.
Redirect to event page after checking out in WooCommerce
<?php
add_action( 'woocommerce_thankyou', function( $order_id ){
$order = wc_get_order( $order_id );
$has_tickets = get_post_meta( $order_id, '_tribe_has_tickets', true );
if ( empty( $has_tickets ) || ! $has_tickets ) {
return;
}
$items = $order->get_items();
$event = false;
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
$event = get_post_meta( $product_id, '_tribe_wooticket_for_event', true );
if ( ! empty( $event ) ) {
break;
}
}
if ( ! $order->has_status( 'failed' ) && $event ) {
wp_safe_redirect( get_permalink( $event ) );
exit;
}
});
@skyshab
Copy link
Author

skyshab commented Jul 26, 2021

Note that a WooCommerce order can have tickets from multiple events. This will redirect to the event from the first ticket product encountered in the order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment