Tribe__Tickets_Plus__Commerce__EDD__Cart
EDD cart class
Source
File: src/Tribe/Commerce/EDD/Cart.php
class Tribe__Tickets_Plus__Commerce__EDD__Cart extends Tribe__Tickets_Plus__Commerce__Abstract_Cart {
/**
* Hook relevant actions and filters
*
* @since 4.9
*/
public function hook() {
parent::hook();
add_filter( 'tribe_tickets_attendee_registration_checkout_url', [ $this, 'maybe_filter_attendee_registration_checkout_url' ], 9 );
add_filter( 'tribe_tickets_tickets_in_cart', [ $this, 'get_tickets_in_cart' ] );
add_filter( 'tribe_providers_in_cart', [ $this, 'providers_in_cart' ], 11 );
}
/**
* 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 string
*/
public function maybe_filter_attendee_registration_checkout_url( $checkout_url ) {
if ( empty( edd_get_cart_contents() ) ) {
return $checkout_url;
}
/** @var \Tribe__Tickets_Plus__Commerce__EDD__Main $commerce_edd */
$commerce_edd = tribe( 'tickets-plus.commerce.edd' );
if ( $commerce_edd->attendee_object !== tribe_get_request_var( 'provider' ) ) {
return $checkout_url;
}
$attendee_reg = tribe( 'tickets.attendee_registration' );
$on_registration_page = $attendee_reg->is_on_page() || $attendee_reg->is_using_shortcode();
// we only want to override if we are on the cart page or the attendee registration page
if ( ! $on_registration_page ) {
return $checkout_url;
}
return edd_get_checkout_uri();
}
/**
* Hooked to tribe_providers_in_cart adds EDD as a provider for checks if there are EDD items in the "cart"
*
* @since 4.10.2
*
* @param array $providers
* @return array providers, with EDD optionally added
*/
public function providers_in_cart( $providers ) {
if ( empty( edd_get_cart_contents() ) ) {
return $providers;
}
$providers[] = 'EDD';
return $providers;
}
/**
* Get all tickets currently in the cart.
*
* @since 4.9
*
* @param array $tickets Array indexed by ticket id with quantity as the value
*
* @return array
*/
public function get_tickets_in_cart( $tickets = array() ) {
$contents = edd_get_cart_contents();
if ( empty( $contents ) ) {
return $tickets;
}
foreach ( $contents as $item ) {
$edd_check = get_post_meta( $item['id'], tribe( 'tickets-plus.commerce.edd' )->event_key, true );
if ( empty( $edd_check ) ) {
continue;
}
$tickets[ $item['id'] ] = $item['quantity'];
}
return $tickets;
}
}
Changelog
| Version | Description |
|---|---|
| 4.9 | Introduced. |
Methods
- add_ticket_to_cart — Handles the process of adding a ticket product to the cart.
- commerce_get_tickets_in_cart — Get all tickets currently in the cart for Commerce.
- commerce_update_tickets_in_cart — Update tickets in EDD cart for Commerce.
- get_cart_url — Get EDD Cart URL.
- get_checkout_url — Get EDD Checkout URL.
- get_tickets_in_cart — Get all tickets currently in the cart.
- hook — Hook relevant actions and filters
- maybe_filter_attendee_registration_checkout_url — Hijack URL if on cart and there are attendee registration fields that need to be filled out
- providers_in_cart — Hooked to tribe_providers_in_cart adds EDD as a provider for checks if there are EDD items in the "cart"
- remove_meta_for_ticket — Remove meta for ticket when removed from the cart.