'no', 'default_checked' => 'no', 'subscribe_newsletter' => 'no', 'newsletter_lists' => array(), 'text' => '', ), $s ); } public function ajax_save() { AIEO_DMM::verify_ajax_request(); $enabled = ( isset( $_POST['enabled'] ) && '1' === (string) $_POST['enabled'] ) ? 'yes' : 'no'; $default_checked = ( isset( $_POST['default_checked'] ) && '1' === (string) $_POST['default_checked'] ) ? 'yes' : 'no'; $subscribe_newsletter = ( isset( $_POST['subscribe_newsletter'] ) && '1' === (string) $_POST['subscribe_newsletter'] ) ? 'yes' : 'no'; $newsletter_lists = array(); if ( isset( $_POST['newsletter_lists'] ) && is_array( $_POST['newsletter_lists'] ) ) { foreach ( wp_unslash( $_POST['newsletter_lists'] ) as $lid ) { $lid = sanitize_text_field( (string) $lid ); if ( '' !== $lid ) { $newsletter_lists[] = $lid; } } } $text = isset( $_POST['text'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['text'] ) ) : ''; update_option( self::OPTION_KEY, array( 'enabled' => $enabled, 'default_checked' => $default_checked, 'subscribe_newsletter' => $subscribe_newsletter, 'newsletter_lists' => $newsletter_lists, 'text' => $text, ), false ); wp_send_json_success( array( 'enabled' => $enabled, 'default_checked' => $default_checked, 'subscribe_newsletter' => $subscribe_newsletter, 'newsletter_lists' => $newsletter_lists, 'text' => $text ) ); } public function render_subtab() { $s = self::settings(); $nl_available = class_exists( 'AIEO_Newsletter_Manager' ) && AIEO_Newsletter_Manager::available(); $nl_lists = $nl_available ? AIEO_Newsletter_Manager::public_lists() : array(); $form_id = 'aieo-card-contact-optin-checkbox-form'; list( $open, $close ) = AIEO_DMM_UI::card( array( 'anchor' => 'contact-optin-checkbox', 'title' => __( 'Opt-in checkbox', 'ai-eshop-optimizer' ), 'description' => __( 'Show a marketing opt-in checkbox at checkout. When a shopper checks it, they are opted in to our marketing emails on order placement (the same consent the My-Account “Email & marketing preferences” toggle manages — it clears any email suppression). Enable “Also subscribe them to our newsletter” below to make the SAME box also register a brand-new shopper in our newsletter database (existing subscribers are left untouched; no confirmation email is sent). Customers can manage newsletter and offers separately in My-Account. Leaving it unchecked never opts anyone out (the box only ever opts in).', 'ai-eshop-optimizer' ), 'class' => 'aieo-contact-optin-settings', 'footer' => class_exists( '\Rooster\Admin\States' ) ? \Rooster\Admin\States::save_button( $form_id ) : '', ) ); echo $open; $row = static function ( array $field ) { return \Rooster\Admin\Ui::field_row( $field ); }; if ( $nl_available ) { $newsletter = AIEO_Kit::check( 'subscribe_newsletter', __( 'Also subscribe them to our newsletter', 'ai-eshop-optimizer' ), 'yes' === $s['subscribe_newsletter'], array( 'id' => 'aieo-optin-subscribe-newsletter', 'attrs' => array( 'aria-describedby' => 'aieo-optin-subscribe-newsletter-help' ) ) ) . '

' . esc_html__( 'When ticked, a NEW checkout subscriber is registered in the newsletter subscriber database (nothing more). Shoppers who are already subscribers are left untouched, and no confirmation email is sent.', 'ai-eshop-optimizer' ) . '

'; if ( ! empty( $nl_lists ) ) { $chosen = array_map( 'strval', (array) $s['newsletter_lists'] ); $newsletter .= '

' . esc_html__( 'Also add new subscribers to these public lists by default (optional):', 'ai-eshop-optimizer' ) . '

'; foreach ( $nl_lists as $l ) { $newsletter .= ''; } $newsletter .= '
'; } } else { $newsletter = \Rooster\Admin\Ui::notice( esc_html__( 'The Newsletter Plugin is not active, so subscribing to the newsletter from checkout is unavailable.', 'ai-eshop-optimizer' ), 'info', array( 'inline' => true ) ); } ob_start(); echo '
' . $row( array( 'id' => 'aieo-optin-enabled', 'label' => __( 'Enable checkbox', 'ai-eshop-optimizer' ), 'control' => AIEO_Kit::check( 'enabled', __( 'Show the marketing opt-in checkbox at checkout', 'ai-eshop-optimizer' ), 'yes' === $s['enabled'], array( 'id' => 'aieo-optin-enabled' ) ), ) ) . $row( array( 'id' => 'aieo-optin-default-checked', 'label' => __( 'Pre-checked', 'ai-eshop-optimizer' ), 'control' => AIEO_Kit::check( 'default_checked', __( 'Tick the box by default', 'ai-eshop-optimizer' ), 'yes' === $s['default_checked'], array( 'id' => 'aieo-optin-default-checked' ) ), 'help' => __( 'A ticked box counts as consent to your marketing e-mails, also when this setting ticked it. In the EU a pre-ticked box is not valid consent under the GDPR (the Planet49 ruling): the choice is yours. A signed-in customer who has opted out is never shown it ticked.', 'ai-eshop-optimizer' ), ) ) . $row( array( 'id' => 'aieo-optin-newsletter', 'group' => true, 'label' => __( 'Newsletter', 'ai-eshop-optimizer' ), 'control' => $newsletter, ) ) . $row( array( 'id' => 'aieo-optin-text', 'label' => __( 'Checkbox text', 'ai-eshop-optimizer' ), 'control' => \Rooster\Admin\Ui::input( 'text', (string) $s['text'], array( 'id' => 'aieo-optin-text', 'placeholder' => self::default_text() ) ), ) ) . '
'; echo AIEO_DMM_UI::card_form( 'aieo_dmm_contact_optin_save', $this->get_id(), $form_id, (string) ob_get_clean() ); echo $close; } }