Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active September 12, 2018 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cliffordp/9a457b724e38b3036f8d48adc90930ed to your computer and use it in GitHub Desktop.
Save cliffordp/9a457b724e38b3036f8d48adc90930ed to your computer and use it in GitHub Desktop.
Event Tickets Plus: WooCommerce: Force all tickets to be "Sold Individually".
<?php
/**
* Event Tickets Plus: WooCommerce: Force all tickets to be "Sold Individually".
*
* By default, this limits the purchase quantity to 1, but this is quantity is
* filterable with `woocommerce_add_to_cart_sold_individually_quantity`.
*
* @see Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_event_for_ticket()
* @see WC_Product::is_sold_individually()
* @see WC_Cart::add_to_cart()
*
* @link https://gist.github.com/cliffordp/9a457b724e38b3036f8d48adc90930ed
*/
function cliff_et_force_woo_tix_sold_individually( $sold_individually, $wc_product_instance ) {
if (! class_exists( 'Tribe__Tickets_Plus__Commerce__WooCommerce__Main' ) ) {
return $sold_individually;
}
$wootix = new Tribe__Tickets_Plus__Commerce__WooCommerce__Main;
if ( empty( $wc_product_instance->get_id() ) ) {
return false;
}
if ( $wootix->get_event_for_ticket( $wc_product_instance->get_id() ) ) {
return true;
} else {
return $sold_individually;
}
}
add_filter( 'woocommerce_is_sold_individually', 'cliff_et_force_woo_tix_sold_individually', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment