Payouts::generate_payouts_for_order( int|TribeCommunityTicketsWC_Order $order )

Generate all payouts for an order.


Parameters #

$order

(int|TribeCommunityTicketsWC_Order) (Required) WooCommerce Order object or ID.


Top ↑

Source #

File: src/Tribe/Payouts.php

	public function generate_payouts_for_order( $order ) {
		if ( ! $this->is_split_payments_enabled() ) {
			return;
		}

		if ( empty( $order ) ) {
			return;
		}

		$order_id = is_numeric( $order ) ? $order : $order->get_id();

		if ( empty( $order_id ) ) {
			return;
		}

		$this->save_meta( $order_id );

		try {
			// Attempt to NOT create duplicates
			$repository = tribe_payouts();
			$repository->by( 'order', $order_id );
			$repository->set_found_rows( true );

			$found = $repository->found();
		} catch ( \Tribe__Repository__Usage_Error $exception ) {
			// There was an error, skip processing.
			return;
		}

		if ( 0 < $found ) {
			return;
		}

		/** @var Order $payout_order */
		$payout_order = tribe( 'community-tickets.payouts.order' );

		// Setup order from ID.
		$payout_order->hydrate_from_order( $order_id );

		// Get receivers.
		$receivers = $payout_order->get_receivers();

		// Loop through receivers to save initial payouts.
		foreach ( $receivers as $receiver ) {
			// Skip receiver if they do not need a payout.
			if ( $receiver->get_total() <= 0 ) {
				continue;
			}

			/** @var Payout $payout */
			$payout = tribe( 'community-tickets.payouts.payout' );

			// Setup payout from receiver.
			$payout->hydrate_from_receiver( $receiver );

			$payout->save();
		}
	}

Top ↑

Changelog #

Changelog
Version Description
4.7.0 Introduced.