Give_Tokens::parse_give_donation_token( $value,  $pieces,  $recipe_id,  $trigger_data, int $user_id,  $replace_args )


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(int) (Required)

$replace_args

(Required)


Top ↑

Return Return

(mixed)


Source Source

File: src/integrations/give/tokens/give-tokens.php

	public function parse_give_donation_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
		$tokens = [
			'GIVEWPMAKEDONATION',
			'ACTUALDONATEDAMOUNT',
			'DONATIONFORM',
		];

		if ( $pieces && isset( $pieces[2] ) ) {
			$meta_field = $pieces[2];

			if ( ! empty( $meta_field ) && in_array( $meta_field, $tokens, false ) ) {
				if ( $trigger_data ) {
					foreach ( $trigger_data as $trigger ) {
						switch ( $meta_field ) {
							case 'NUMBERCOND':
								$value = $trigger['meta']['NUMBERCOND_readable'];
								break;
							default:
								global $wpdb;
								$meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->prefix}uap_trigger_log_meta WHERE meta_key = %s AND automator_trigger_id = %d AND automator_trigger_log_id = %d ORDER BY ID DESC LIMIT 0,1", $meta_field, $trigger['ID'], $replace_args['trigger_log_id'] ) );
								if ( ! empty( $meta_value ) ) {
									$value = maybe_unserialize( $meta_value );
								}
								break;
						}
					}
				}
			} else {
				if ( 'DONATIONFORM' === $pieces[1] ) {
					$billing_fields = [ 'address1', 'address2', 'city', 'state', 'zip', 'country' ];
					global $wpdb;
					if ( $trigger_data ) {
						foreach ( $trigger_data as $trigger ) {
							$field_keys = explode( '|', $pieces[2] );
							$field_key  = isset( $field_keys[1] ) ? $field_keys[1] : '';
							if ( ! empty( $field_key ) && ! in_array( $field_key, $billing_fields, true ) ) {
								$meta_key   = 'payment_data';
								$meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->prefix}uap_trigger_log_meta WHERE meta_key = %s AND automator_trigger_id = %d AND automator_trigger_log_id = %d  ORDER BY ID DESC LIMIT 0,1", $meta_key, $trigger['ID'], $replace_args['trigger_log_id'] ) );
								if ( ! empty( $meta_value ) ) {
									$meta_value  = maybe_unserialize( $meta_value );
									$form_fields = Automator()->helpers->recipe->give->get_form_fields_and_ffm( $meta_value['give_form_id'] );
									$form_field  = isset( $form_fields[ $field_key ] ) ? $form_fields[ $field_key ] : array();
									if ( ! empty( $form_field ) ) {
										if ( ! empty( $meta_value ) ) {
											if ( isset( $meta_value[ $form_field['key'] ] ) ) {
												$value = $meta_value[ $form_field['key'] ];
											} elseif ( isset( $meta_value['user_info'][ $form_field['key'] ] ) ) {
												$value = $meta_value['user_info'][ $form_field['key'] ];
											}
										}
									}

								}
							} elseif ( ! empty( $field_key ) && in_array( $field_key, $billing_fields, true ) ) {
								$meta_key   = 'payment_id';
								$meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->prefix}uap_trigger_log_meta WHERE meta_key = %s AND automator_trigger_id = %d AND automator_trigger_log_id = %d  ORDER BY ID DESC LIMIT 0,1", $meta_key, $trigger['ID'], $replace_args['trigger_log_id'] ) );
								if ( ! empty( $meta_value ) && function_exists( 'give_get_meta' ) ) {
									$inner_meta_key = '_give_donor_billing_' . $field_key;
									$value          = give_get_meta( $meta_value, $inner_meta_key, true );
								}
							}
						}
					}
				}
			}
		}

		return $value;
	}