Tribe__Tickets_Plus__Commerce__WooCommerce__Main::handle_delete_post( int|WP_Post $post )

When a user deletes a ticket (product) we want to store a copy of the product name, so we can show it in the attendee list for an event.


Parameters

$post

(int|WP_Post) (Required)


Top ↑

Source

File: src/Tribe/Commerce/WooCommerce/Main.php

	public function handle_delete_post( $post ) {
		if ( is_numeric( $post ) ) {
			$post = WP_Post::get_instance( $post );
		}

		if ( ! $post instanceof WP_Post ) {
			return false;
		}

		// Bail if it's not a Product
		if ( 'product' !== $post->post_type ) {
			return;
		}

		// Bail if the product is not a Ticket
		$event = get_post_meta( $post->ID, $this->event_key, true );

		if ( ! $event ) {
			return;
		}

		$attendees = $this->get_attendees_by_id( $event );

		foreach ( (array) $attendees as $attendee ) {
			if ( $attendee['product_id'] == $post->ID ) {
				update_post_meta( $attendee['attendee_id'], $this->deleted_product, esc_html( $post->post_title ) );
			}
		}
	}