position = WooMailerLiteOptions::get('settings.selectedCheckoutPosition', 'checkout_billing'); $this->label = strip_tags(stripslashes(WooMailerLiteOptions::get('settings.checkoutLabel'))); $this->hidden = WooMailerLiteOptions::get('settings.checkoutHidden'); $this->preselect = WooMailerLiteOptions::get('settings.checkoutPreselect'); $this->pluginEnabled = WooMailerLiteOptions::get('enabled'); $this->checkoutEnabled = WooMailerLiteOptions::get('settings.subscribeOnCheckout'); $this->group = WooMailerLiteOptions::get('group' , false); } public function addMlSubscribeCheckbox() { if (!$this->pluginEnabled || !$this->checkoutEnabled || ($this->position == 'checkout_billing_email') || !$this->group) { return; } if ($this->hidden) { ?> 'checkbox', 'label' => __($this->label, 'woo-mailerlite'), 'checked' => $this->preselect ? 'checked' : '', 'label_class' => ['woocommerce-form__label-for-checkbox'], ), (bool) $this->preselect); } } public function addBillingCheckoutFields($fields) { if (!$this->pluginEnabled || !$this->checkoutEnabled || !$this->group || ($this->position !== 'checkout_billing_email')) { return $fields; } $new_billing_fields = []; foreach ($fields['billing'] as $key => $field) { $new_billing_fields[$key] = $field; if ($key === 'billing_email') { $new_billing_fields['woo_ml_subscribe'] = [ 'type' => (!$this->hidden) ? 'checkbox' : 'hidden', 'default' => $this->preselect, 'required' => false, 'label_class' => ['woocommerce-form__label-for-checkbox'], ]; if (!$this->hidden) { $new_billing_fields['woo_ml_subscribe']['label'] = __($this->label, 'woo-mailerlite'); } else { $new_billing_fields['woo_ml_subscribe']['custom_attributes'] = [ 'checked' => 'checked', ]; } } } $fields['billing'] = $new_billing_fields; return $fields; } public function reloadCheckout() { try { if (!function_exists('WC') || !is_object(WC()->session)) { return false; } if ($this->requestHas('ml_checkout') && (ctype_digit($this->request['ml_checkout']) || wp_is_uuid($this->request['ml_checkout']))) { $escaped = db()->esc_like($this->request['ml_checkout']); $escaped = '%checkout_id":"' . addcslashes($escaped, '%_') . '"%'; $cart = WooMailerLiteCart::where('data', 'like', $escaped)->first(); if ($cart && $cart->exists()) { $cartData = $cart->data; unset($cartData['checkout_id']); WC()->session->set('cart', $cartData); } } } catch (Throwable $e) { WooMailerLiteLog()->error('Error restoring cart from checkout ID: ' . $e->getMessage(), ['trace' => $e->getTraceAsString()]); } return true; } }