Autonami_Helpers::add_tag_to_contact( mixed $email, mixed $tag_id, mixed $tag_readable )

Method add_tag_to_contact


Parameters Parameters

$email

(Required)

$tag_id

(Required)

$tag_readable

(Required)


Top ↑

Return Return

(void)


Source Source

File: src/integrations/autonami/helpers/autonami-helpers.php

	public function add_tag_to_contact( $email, $tag_id, $tag_readable ) {

		$tags_to_add = array(
			array(
				'id' => $tag_id,
			),
		);

		$autonami_contact = new \BWFCRM_Contact( $email );

		$result = $autonami_contact->add_tags( $tags_to_add );

		if ( is_wp_error( $result ) ) {
			throw new \Exception( $result->get_error_message() );
		}

		if ( empty( $result ) ) {
			/* translators: %s - the tag name. */
			throw new \Exception( sprintf( __( 'User already has the %s tag', 'uncanny-automator' ), $tag_readable ) );
		}

		$autonami_contact->save();

	}