Last active
May 28, 2019 08:03
-
-
Save rafsuntaskin/61baf0b5bfd4223d54be46acddd81f32 to your computer and use it in GitHub Desktop.
ET+ Fix coupon apply bug || AR page saving to empty page
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
<?php | |
add_filter( "woocommerce_get_checkout_url", "rt_fix_maybe_filter_checkout_url_to_attendee_registration", 20); | |
/** | |
* Hooked to the woocommerce_get_checkout_url filter to hijack URL if on cart and there | |
* are attendee registration fields that need to be filled out | |
* | |
* @since 4.9 | |
* | |
* @param string $checkout_url | |
* | |
* @return null|string | |
*/ | |
function rt_fix_maybe_filter_checkout_url_to_attendee_registration( $checkout_url ) { | |
$on_registration_page = tribe( 'tickets.attendee_registration' )->is_on_page(); | |
$shortcode_page = tribe( 'tickets.attendee_registration' )->is_using_shortcode(); | |
// we only want to skip url override in our registration page | |
if ( $on_registration_page || $shortcode_page ) { | |
return $checkout_url; | |
} | |
/** @var \Tribe__Tickets_Plus__Commerce__WooCommerce__Main $commerce_woo */ | |
$commerce_woo = tribe( 'tickets-plus.commerce.woo' ); | |
$provider = tribe_get_request_var( 'provider' ); | |
// Return default URL if provider is not WC | |
if ( !empty( $provider ) && $commerce_woo->attendee_object !== $provider ) { | |
return $checkout_url; | |
} | |
$cart_tickets = tribe( 'tickets-plus.commerce.woo.cart' )->get_tickets_in_cart(); | |
$cart_has_meta = Tribe__Tickets_Plus__Main::instance()->meta()->cart_has_meta( $cart_tickets ); | |
// If cart has no meta, return checkout url | |
if ( ! $cart_has_meta ) { | |
return $checkout_url; | |
} | |
$url = add_query_arg( 'provider', $commerce_woo->attendee_object, tribe( 'tickets.attendee_registration' )->get_url() ); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment