Created
March 12, 2020 15:54
-
-
Save rafsuntaskin/5f760bef8b9f437e083ba64603130852 to your computer and use it in GitHub Desktop.
remove Provider URL from Woo Checkout URL fix for ET 4.11.4
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 | |
//remove the original filter | |
add_action( 'wp', 'rt_et_remove_tribe_filter', 99 ); | |
function rt_et_remove_tribe_filter() { | |
$woo_cart = tribe( 'tickets-plus.commerce.woo.cart' ); | |
remove_filter( 'woocommerce_get_checkout_url', [ | |
$woo_cart, | |
'maybe_filter_checkout_url_to_attendee_registration' | |
], 50 ); | |
add_filter( 'woocommerce_get_checkout_url', 'rt_maybe_filter_checkout_url_to_attendee_registration_without_provider', 55, 1 ); | |
} | |
function rt_maybe_filter_checkout_url_to_attendee_registration_without_provider($checkout_url){ | |
// If in the admin area, do not filter. | |
error_log(print_r($checkout_url, 1)); | |
$woo_cart = tribe( 'tickets-plus.commerce.woo.cart' ); | |
if ( is_admin() ) { | |
return $checkout_url; | |
} | |
/** @var \Tribe__Tickets__Attendee_Registration__Main $attendee_reg */ | |
$attendee_reg = tribe( 'tickets.attendee_registration' ); | |
global $wp_query; | |
// If on the AR page, do not filter. | |
if ( | |
empty( $wp_query->query_vars ) | |
|| $attendee_reg->is_on_page() | |
|| $attendee_reg->is_cart_rest() | |
|| $attendee_reg->is_using_shortcode() | |
) { | |
return $checkout_url; | |
} | |
$ticket_updated = false; | |
$wc_session = WC()->session; | |
if ( $wc_session ) { | |
$ticket_updated = filter_var( $wc_session->get( 'tribe_ar_ticket_updated' ), FILTER_VALIDATE_BOOLEAN ); | |
} | |
if ( ! $ticket_updated ) { | |
$cart_tickets = $woo_cart->get_tickets_in_cart(); | |
/** @var \Tribe__Tickets_Plus__Meta__Contents $meta_contents */ | |
$meta_contents = tribe( 'tickets-plus.meta.contents' ); | |
$meta_up_to_date = $meta_contents->is_stored_meta_up_to_date( $cart_tickets ); | |
// If meta is up to date, do not filter. | |
if ( $meta_up_to_date ) { | |
return $checkout_url; | |
} | |
/** @var \Tribe__Tickets_Plus__Meta $tickets_meta */ | |
$tickets_meta = tribe( 'tickets-plus.main' )->meta(); | |
$cart_has_meta = $tickets_meta->cart_has_meta( $cart_tickets ); | |
// If cart has no meta, do not filter. | |
if ( ! $cart_has_meta ) { | |
return $checkout_url; | |
} | |
} | |
/** @var \Tribe__Tickets_Plus__Commerce__WooCommerce__Main $woo */ | |
$woo = tribe( 'tickets-plus.commerce.woo' ); | |
$ticket_provider = $woo->attendee_object; | |
$checkout_url = $attendee_reg->get_url(); | |
$checkout_url = add_query_arg( 'provider', $ticket_provider, $checkout_url ); | |
return $checkout_url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment