e 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 .= ""; $checkbox .= ""; } if (is_checkout() && $hide_optin_for_subscriber) { $checkbox = ''; } echo apply_filters( 'mailchimp_woocommerce_newsletter_field', $checkbox, $status, $label); // Render SMS consent fields after newsletter checkbox $this->applySmsConsentField(); } } /** * Render SMS consent checkbox and phone field for classic checkout */ public function applySmsConsentField() { // Check if SMS is enabled in settings if (!$this->isSmsEnabled()) { return; } // Check if merchant has approved SMS application if (!$this->merchantHasSmsApproved()) { return; } // Compliance: checkbox must always be unchecked by default, label and disclaimer are fixed $sms_label = __('Text me with news and offers', 'mailchimp-for-woocommerce'); $audience_name = $this->getAudienceName(); $prefix = !empty($audience_name) ? $audience_name . ' – ' : ''; $in_sentence = !empty($audience_name) ? $audience_name : 'us'; $sms_disclaimer = $prefix . __('By providing your phone number, you agree to receive promotional and marketing messages (e.g. abandoned carts), notifications, and customer service communications from '.$in_sentence.'. Message and data rates map apply. Consent is not a condition of purchase. Message frequency varies. Text HELP for help. Text STOP to cancel. See Terms and Privacy Policy.', 'mailchimp-for-woocommerce'); // Always unchecked by default per compliance $sms_status = false; $sms_phone = ''; $hide_sms_for_subscriber = false; // Check logged-in user's SMS subscription status if (is_user_logged_in()) { $user_sms_status = get_user_meta(get_current_user_id(), 'mailchimp_woocommerce_sms_subscribed', true); $sms_phone = get_user_meta(get_current_user_id(), 'mailchimp_woocommerce_sms_phone', true); $hide_sms_for_subscriber = $user_sms_status === true || $user_sms_status === '1'; if ($user_sms_status === '' || $user_sms_status === null) { $sms_status = false; } else { $sms_status = (bool) $user_sms_status; } } // Don't show if already subscribed to SMS if (is_checkout() && $hide_sms_for_subscriber) { return; } // Build SMS consent HTML $sms_html = ''; $sms_html .= ''; // Get SMS sending countries for JS $sms_countries = $this->getSmsSendingCountries(); $sms_countries_json = !empty($sms_countries) ? json_encode($sms_countries) : '[]'; // JavaScript to toggle phone field visibility, validation, and country filtering $sms_html .= ''; echo apply_filters('mailchimp_woocommerce_sms_consent_field', $sms_html, $sms_status, $sms_label); } /** * Check if SMS marketing is enabled * * @return bool */ public function isSmsEnabled() { return (bool) $this->getOption('mailchimp_sms_enabled', false); } /** * Check if merchant has an approved SMS application * * @return bool */ public function merchantHasSmsApproved() { try { if (!mailchimp_is_configured()) { return false; } $list_id = mailchimp_get_list_id(); if (!$list_id) { return false; } $api = mailchimp_get_api(); $sms_status = $api->getCachedSmsApplicationStatus($list_id); return $sms_status && !empty($sms_status['enabled']); } catch (Exception $e) { return false; } } /** * Get SMS sending countries for the merchant * * @return array */ public function getSmsSendingCountries() { try { if (!mailchimp_is_configured()) { return array(); } $list_id = mailchimp_get_list_id(); if (!$list_id) { return array(); } $api = mailchimp_get_api(); $sms_status = $api->getCachedSmsApplicationStatus($list_id); if ($sms_status && !empty($sms_status['sending_countries'])) { return $sms_status['sending_countries']; } return array(); } catch (Exception $e) { return array(); } } /** * Check if a country is eligible for SMS * * @param string $country_code 2-letter country code * @return bool */ public function isCountryEligibleForSms($country_code) { $sending_countries = $this->getSmsSendingCountries(); if (empty($sending_countries)) { // If no countries configured, allow all (graceful fallback) return true; } return in_array(strtoupper($country_code), $sending_countries, true); } /** * Get the audience name for disclaimer * * @return string */ protected function getAudienceName() { try { if (!mailchimp_is_configured()) { return ''; } $list_id = mailchimp_get_list_id(); if (!$list_id) { return ''; } $api = mailchimp_get_api(); $list = $api->getList($list_id); return isset($list['name']) ? $list['name'] : ''; } catch (Exception $e) { return ''; } } /** * @param $order_id * @param $posted */ public function processNewsletterField($order_id, $posted) { $this->handleStatus($order_id); $this->handleSmsStatus($order_id); } /** * @param $order */ public function processPayPalNewsletterField($order) { $this->handleStatus($order->get_id()); $this->handleSmsStatus($order->get_id()); } /** * @param $sanitized_user_login * @param $user_email * @param $reg_errors */ public function processRegistrationForm($sanitized_user_login, $user_email, $reg_errors) { if (defined('WOOCOMMERCE_CHECKOUT')) { return; // Ship checkout } $this->handleStatus(); $this->handleSmsStatus(); } /** * @param null $order_id * @return bool|int */ protected function handleStatus($order_id = null) { $post_key = 'mailchimp_woocommerce_newsletter'; $meta_key = 'mailchimp_woocommerce_is_subscribed'; $logged_in = is_user_logged_in(); // if the post key is available we use it - otherwise we null it out. $status = isset($_POST[$post_key]) ? (int) $_POST[$post_key] : null; // if the status is null, we don't do anything if ($status === null) { return false; } // if we passed in an order id, we update it here. if ($order_id) { MailChimp_WooCommerce_HPOS::update_order_meta($order_id, $meta_key, $status); //update_post_meta($order_id, $meta_key, $status); } // if the user is logged in, we will update the status correctly. if ($logged_in) { update_user_meta(get_current_user_id(), $meta_key, $status); return $status; } return false; } /** * Handle SMS subscription status from classic checkout * * @param null $order_id * @return bool */ protected function handleSmsStatus($order_id = null) { // Check if SMS is enabled if (!$this->isSmsEnabled()) { return false; } $sms_checkbox_key = 'mailchimp_woocommerce_sms_subscribe'; $sms_phone_key = 'mailchimp_woocommerce_sms_phone'; $sms_subscribed_meta = 'mailchimp_woocommerce_sms_subscribed'; $sms_phone_meta = 'mailchimp_woocommerce_sms_phone'; $logged_in = is_user_logged_in(); // Get SMS consent status from POST $sms_subscribed = isset($_POST[$sms_checkbox_key]) ? (bool) $_POST[$sms_checkbox_key] : false; $sms_phone = isset($_POST[$sms_phone_key]) ? sanitize_text_field($_POST[$sms_phone_key]) : ''; // Sanitize phone number - keep only + and digits $sms_phone = preg_replace('/[^\+\d]/', '', $sms_phone); // If they didn't check the box or didn't provide a phone, don't save anything if (!$sms_subscribed || empty($sms_phone)) { return false; } // Update order meta if ($order_id) { MailChimp_WooCommerce_HPOS::update_order_meta($order_id, $sms_subscribed_meta, true); MailChimp_WooCommerce_HPOS::update_order_meta($order_id, $sms_phone_meta, $sms_phone); } // Update user meta if logged in if ($logged_in) { update_user_meta(get_current_user_id(), $sms_subscribed_meta, true); update_user_meta(get_current_user_id(), $sms_phone_meta, $sms_phone); } return true; } /** * Get SMS subscription data from order * * @param int $order_id * @return array|false */ public static function getSmsDataFromOrder($order_id) { $wc_order = wc_get_order($order_id); if (!$wc_order) { return false; } $sms_subscribed = $wc_order->get_meta('mailchimp_woocommerce_sms_subscribed'); $sms_phone = $wc_order->get_meta('mailchimp_woocommerce_sms_phone'); if (!$sms_subscribed || empty($sms_phone)) { return false; } return array( 'subscribed' => (bool) $sms_subscribed, 'phone' => $sms_phone, ); } /** * Get SMS subscription data from user * * @param int $user_id * @return array|false */ public static function getSmsDataFromUser($user_id) { $sms_subscribed = get_user_meta($user_id, 'mailchimp_woocommerce_sms_subscribed', true); $sms_phone = get_user_meta($user_id, 'mailchimp_woocommerce_sms_phone', true); if (!$sms_subscribed || empty($sms_phone)) { return false; } return array( 'subscribed' => (bool) $sms_subscribed, 'phone' => $sms_phone, ); } } 1 - Uncaught Error: Class 'MailChimp_Newsletter' not found in /home/st20space2tech/public_html/site/wp-content/plugins/mailchimp-for-woocommerce/includes/class-mailchimp-woocommerce.php:349 Stack trace: #0 /home/st20space2tech/public_html/site/wp-content/plugins/mailchimp-for-woocommerce/includes/class-mailchimp-woocommerce.php(132): MailChimp_WooCommerce->activateMailChimpNewsletter() #1 /home/st20space2tech/public_html/site/wp-content/plugins/mailchimp-for-woocommerce/bootstrap.php(1842): MailChimp_WooCommerce->__construct('production', '6.1.1') #2 /home/st20space2tech/public_html/site/wp-content/plugins/mailchimp-for-woocommerce/bootstrap.php(1847): run_mailchimp_woocommerce() #3 /home/st20space2tech/public_html/site/wp-includes/class-wp-hook.php(341): mailchimp_on_all_plugins_loaded('') #4 /home/st20space2tech/public_html/site/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array) #5 /home/st20space2tech/public_html/site/wp-includes/plugin.php(522): WP_Hook->do_action(Array) #6 /home/st20spac - /home/st20space2tech/public_html/site/wp-content/plugins/mailchimp-for-woocommerce/includes/class-mailchimp-woocommerce.php - 349