Automattic\WooCommerce\Internal\Admin\Schedulers
MailchimpScheduler::run()
Attempt to subscribe store_email to MailChimp.
Метод класса: MailchimpScheduler{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$MailchimpScheduler = new MailchimpScheduler(); $MailchimpScheduler->run();
Код MailchimpScheduler::run() MailchimpScheduler::run WC 9.3.3
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; } $country_code = WC()->countries->get_base_country(); $country_name = WC()->countries->countries[ $country_code ] ?? 'N/A'; $state = WC()->countries->get_base_state(); $state_name = WC()->countries->states[ $country_code ][ $state ] ?? 'N/A'; $address = array( // Setting N/A for addr1, city, state, zipcode and country as they are // required fields. Setting '' doesn't work. 'addr1' => 'N/A', 'addr2' => '', 'city' => 'N/A', 'state' => $state_name, 'zip' => 'N/A', 'country' => $country_name, ); $response = $this->make_request( $profile_data['store_email'], $address ); 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; }