Wc_Tokens::uap_wc_trigger_save_meta_func( $order_id,  $recipe_id,  $args,  $type )


Parameters Parameters

$order_id

(Required)

$recipe_id

(Required)

$args

(Required)

$type

(Required)


Source Source

File: src/integrations/woocommerce/tokens/wc-tokens.php

	public function uap_wc_trigger_save_meta_func( $order_id, $recipe_id, $args, $type ) {
		if ( ! empty( $order_id ) && is_array( $args ) && $recipe_id ) {
			foreach ( $args as $trigger_result ) {
				if ( true === $trigger_result['result'] ) {

					$recipe = Automator()->get_recipes_data( true, $recipe_id );
					if ( is_array( $recipe ) ) {
						$recipe = array_pop( $recipe );
					}
					$triggers = $recipe['triggers'];
					if ( $triggers ) {
						foreach ( $triggers as $trigger ) {
							$trigger_id = $trigger['ID'];
							if ( ! key_exists( 'WOOPRODUCT', $trigger['meta'] )
							     && ! key_exists( 'WOORDERTOTAL', $trigger['meta'] )
							     && ! key_exists( 'WCORDERSTATUS', $trigger['meta'] )
							) {
								continue;
							} else {
								$user_id        = (int) $trigger_result['args']['user_id'];
								$trigger_log_id = (int) $trigger_result['args']['get_trigger_id'];
								$run_number     = (int) $trigger_result['args']['run_number'];

								$args = [
									'user_id'        => $user_id,
									'trigger_id'     => $trigger_id,
									'meta_key'       => 'order_id',
									'meta_value'     => $order_id,
									'run_number'     => $run_number, //get run number
									'trigger_log_id' => $trigger_log_id,
								];

								Automator()->insert_trigger_meta( $args );
							}
						}
					}
				}
			}
		}
	}