setVersion($env->version); return static::$_instance; } /** * @param $checkout */ public function applyNewsletterField($checkout) { // some folks have asked to be able to check out on behalf of customers. I guess this makes sense // if they want to do this, but it needs to be a constant and custom. $allow_admin = defined('MAILCHIMP_ALLOW_ADMIN_NEWSLETTER') && MAILCHIMP_ALLOW_ADMIN_NEWSLETTER; if ($allow_admin || !is_admin()) { $api = mailchimp_get_api(); // get the gdpr fields from the cache - or call it again and save for 5 minutes. $GDPRfields = $api->getCachedGDPRFields(mailchimp_get_list_id()); // if the user has chosen to hide the checkbox, don't do anything. if (($default_setting = $this->getOption('mailchimp_checkbox_defaults', 'check')) === 'hide') { return; } // allow the user to specify the text in the newsletter label. $label = $this->getOption('newsletter_label'); if ($label == '') $label = __('Subscribe to our newsletter', 'mailchimp-for-woocommerce'); // if the user chose 'check' or nothing at all, we default to true. $default_checked = $default_setting === 'check'; $gdpr_statuses = false; $status = $default_checked; $hide_optin_for_subscriber = false; // if the user is logged in, we will pull the 'is_subscribed' property out of the meta for the value. // otherwise we use the default settings. if (is_user_logged_in()) { $status = get_user_meta(get_current_user_id(), 'mailchimp_woocommerce_is_subscribed', true); $gdpr_statuses = get_user_meta(get_current_user_id(), 'mailchimp_woocommerce_gdpr_fields', true); $hide_optin_for_subscriber = $status === true || $status === '1'; /// if the user is logged in - and is already subscribed - just ignore this checkbox. if ($status === '' || $status === null) { $status = $default_checked; } } // echo out the subscription checkbox. $checkbox = '
'; $checkbox .= ''; // only render these fields if it's an array that has valid data. if (!empty($GDPRfields) && is_array($GDPRfields)) { $checkbox .= ""; $checkbox .= __('Please select all the ways you would like to hear from us', 'mailchimp-for-woocommerce'); $checkbox .= "
"; foreach ($GDPRfields as $key => $field) { $marketing_permission_id = $field['marketing_permission_id']; $gdpr_checked = $field['enabled']; $text = $field['text']; // Add to the checkbox output $checkbox .= ""; $checkbox .= ""; $checkbox .= ""; } $checkbox .= "