EDD_ORDERREFUNDED::edd_order_refunded( $order_id )

Validation function when the trigger action is hit


Parameters Parameters

$order_id

(Required)

$refund_id

(Required)

$all_refunded

(Required)


Source Source

File: src/integrations/edd/triggers/edd-orderrefunded.php

	public function edd_order_refunded( $order_id ) {

		$order_detail = edd_get_payment( $order_id );

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

		$post_id    = 0;
		$payment_id = $order_detail->ID;
		$user_id    = edd_get_payment_user_id( $payment_id );

		if ( ! $user_id ) {
			$user_id = wp_get_current_user()->ID;
		}

		$pass_args = [
			'code'    => $this->trigger_code,
			'meta'    => $this->trigger_meta,
			'post_id' => $post_id,
			'user_id' => $user_id,
		];

		$args = Automator()->maybe_add_trigger_entry( $pass_args, false );

		if ( $args ) {
			foreach ( $args as $result ) {
				if ( true === $result['result'] ) {

					$trigger_meta = [
						'user_id'        => $user_id,
						'trigger_id'     => $result['args']['trigger_id'],
						'trigger_log_id' => $result['args']['get_trigger_id'],
						'run_number'     => $result['args']['run_number'],
					];

					$item_names  = array();
					$order_items = edd_get_payment_meta_cart_details( $order_id );
					foreach ( $order_items as $item ) {
						$item_names[] = $item['name'];
					}

					$trigger_meta['meta_key']   = 'EDDORDER_ITEMS';
					$trigger_meta['meta_value'] = maybe_serialize( implode( ',', $item_names ) );
					Automator()->insert_trigger_meta( $trigger_meta );

					$trigger_meta['meta_key']   = 'EDDCUSTOMER_EMAIL';
					$trigger_meta['meta_value'] = maybe_serialize( $order_detail->email );
					Automator()->insert_trigger_meta( $trigger_meta );

					$trigger_meta['meta_key']   = 'EDDORDER_SUBTOTAL';
					$trigger_meta['meta_value'] = maybe_serialize( $order_detail->subtotal );
					Automator()->insert_trigger_meta( $trigger_meta );

					$trigger_meta['meta_key']   = 'EDDORDER_TOTAL';
					$trigger_meta['meta_value'] = maybe_serialize( $order_detail->total );
					Automator()->insert_trigger_meta( $trigger_meta );

					$trigger_meta['meta_key']   = 'EDDORDER_ID';
					$trigger_meta['meta_value'] = maybe_serialize( $order_id );
					Automator()->insert_trigger_meta( $trigger_meta );

					Automator()->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}