Last active
February 11, 2020 16:51
-
-
Save Camwyn/70134d32d98a6efa75644d51a4af6d6e to your computer and use it in GitHub Desktop.
Add detection of the EDD shortcode cart.
This file contains hidden or 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
add_filter( 'tribe_tickets_plus_edd_cart_url', 'detect_edd_shortcode_cart'); | |
/** | |
* Get URL of EDD shortcode cart - if it is in use. | |
* If so use it for the tickets cart URL instead of checkout. | |
* | |
* @return string|null The url or null if the shortcode is not in use. | |
*/ | |
function detect_edd_shortcode_cart() { | |
global $wpdb; | |
/** @var \Tribe__Tickets_Plus__Commerce__EDD__Cart $edd_cart */ | |
$edd_cart = tribe( 'tickets-plus.commerce.edd.cart' ); | |
/** @var \Tribe__Tickets_Plus__Commerce__EDD__Main $ticket_provider */ | |
$ticket_provider = tribe( 'tickets-plus.commerce.edd' ); | |
// Look for a post with the shortcode. | |
$query = "SELECT ID, guid FROM {$wpdb->posts} WHERE post_content LIKE '%[download_cart]%' AND post_status = 'publish' LIMIT 1"; | |
$results = $wpdb->get_results($query); | |
// Parse the results for the permalink. | |
$shortcode_url = ( ! empty( $results[0]->guid ) ) ? get_permalink( $results[0]->ID ) : null; | |
$cart_url = empty( $shortcode_url ) ? $edd_cart->get_checkout_url() : $shortcode_url; | |
// Add some query args for the cart/checkout/attendee registration checks. | |
$cart_url = add_query_arg( | |
[ | |
'eddtickets_process' => 1, | |
'provider' => $ticket_provider::ATTENDEE_OBJECT, | |
], | |
$cart_url | |
); | |
return $cart_url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment