Automattic\WooCommerce\Internal\Admin\Schedulers

MailchimpScheduler::run()publicWC 1.0

Attempt to subscribe store_email to MailChimp.

{} Это метод класса: MailchimpScheduler{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$MailchimpScheduler = new MailchimpScheduler();
$MailchimpScheduler->run();

Код MailchimpScheduler::run() WC 6.9.1

public function run() {
	// Abort if we've already subscribed to MailChimp.
	if ( 'yes' === get_option( self::SUBSCRIBED_OPTION_NAME ) ) {
		return false;
	}

	$profile_data = get_option( 'woocommerce_onboarding_profile' );
	if ( ! isset( $profile_data['is_agree_marketing'] ) || false === $profile_data['is_agree_marketing'] ) {
		return false;
	}

	// Abort if store_email doesn't exist.
	if ( ! isset( $profile_data['store_email'] ) ) {
		return false;
	}

	// Abort if failed requests reaches the threshold.
	if ( intval( get_option( self::SUBSCRIBED_ERROR_COUNT_OPTION_NAME, 0 ) ) >= self::MAX_ERROR_THRESHOLD ) {
		return false;
	}

	$response = $this->make_request( $profile_data['store_email'] );
	if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
		$this->handle_request_error();
		return false;
	}

	$body = json_decode( $response['body'] );
	if ( isset( $body->success ) && true === $body->success ) {
		update_option( self::SUBSCRIBED_OPTION_NAME, 'yes' );
		return true;
	}

	$this->handle_request_error( $body );
	return false;
}