Created
July 26, 2021 13:48
-
-
Save skyshab/d5474fc238329cb6c8519ada986f2b7e to your computer and use it in GitHub Desktop.
Redirect to event page after checking out in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.