Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830
UC_CODESBATCH::user_redeemed_code_batch( $user_id,  $coupon_id,  $res )


Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Parameters Parameters

$user_id

(Required)

$coupon_id

(Required)

$res

(Required)


Source Source

File: src/integrations/uncanny-codes/triggers/uc-codesbatch.php

	public function user_redeemed_code_batch( $user_id, $coupon_id, $result ) {
		global $wpdb;
		if ( ! $user_id ) {
			$user_id = get_current_user_id();
		}
		if ( empty( $user_id ) ) {
			return;
		}
		$recipes        = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		$required_batch = Automator()->get->meta_from_recipes( $recipes, $this->trigger_meta );
		$batch = $wpdb->get_var( $wpdb->prepare( "SELECT g.id FROM `{$wpdb->prefix}uncanny_codes_groups` g LEFT JOIN `{$wpdb->prefix}uncanny_codes_codes` c ON g.ID = c.code_group WHERE c.ID = %d", $coupon_id ) );
		foreach ( $recipes as $recipe_id => $recipe ) {
			foreach ( $recipe['triggers'] as $trigger ) {
				$trigger_id = $trigger['ID'];
				if ( isset( $required_batch[ $recipe_id ] ) && isset( $required_batch[ $recipe_id ][ $trigger_id ] ) ) {
					if ( (string) $batch === (string) $required_batch[ $recipe_id ][ $trigger_id ] ) {
						if ( ! Automator()->is_recipe_completed( $recipe_id, $user_id ) ) {
							$pass_args = array(
								'code'             => $this->trigger_code,
								'meta'             => $this->trigger_meta,
								'ignore_post_id'   => true,
								'recipe_to_match'  => $recipe_id,
								'trigger_to_match' => $trigger_id,
								'user_id'          => $user_id,
								'is_signed_in'     => true,
							);
							$args = Automator()->maybe_add_trigger_entry( $pass_args, false );
							if ( isset( $args ) ) {
								foreach ( $args as $result ) {
									if ( true === $result['result'] ) {
										$trigger_meta = array(
											'user_id'        => $user_id,
											'trigger_id'     => $result['args']['trigger_id'],
											'trigger_log_id' => $result['args']['get_trigger_id'],
											'run_number'     => $result['args']['run_number'],
										);
										$trigger_meta['meta_key']   = $result['args']['trigger_id'] . ':' . $this->trigger_code . ':' . $this->trigger_meta;
										$trigger_meta['meta_value'] = maybe_serialize( $batch );
										Automator()->insert_trigger_meta( $trigger_meta );
										Automator()->maybe_trigger_complete( $result['args'] );
									}
								}
							}
						}
					}
				}
			}
		}
		return;
	}