*/ use MailPoet\Models\Segment; use MailPoet\Models\Subscriber; if ( ! class_exists( 'MPWA_Frontend_Fields' ) ) { class MPWA_Frontend_Fields { //Helper trait use MPWA_Helper_Function; //Properties public $form_position; public $show_form; public $default_status; public $list_ids; private static $_this_class = null; public $user_subscriber; public $show_gdpr_unsub; public $gdpr_unsub_label; public $show_gdpr_consent; public $multi_subscription; public $privacy_page; public $gdpr_consent_text; /** * Initialize the class */ public static function init() { if ( empty( self::$_this_class ) ) { self::$_this_class = new self; } return self::$_this_class; }//Edn of init /** * Constructor */ private function __construct() { //Enable show subscription form $this->show_form = get_option( 'wc_' . $this->tab_slug . '_enable_subscription' ); //Get the form showing position $this->form_position = get_option( 'wc_' . $this->tab_slug . '_subscription_position' ); // Display GDPR unsubscribe option $this->show_gdpr_unsub = get_option( 'wc_' . $this->tab_slug . '_gdpr_show_unsubscribe' ); // GDPR unsubscribe label text $this->gdpr_unsub_label = get_option( 'wc_' . $this->tab_slug . '_gdpr_unsubscribe_label' ); //Check for if user logged in and already subscribed if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); $this->user_subscriber = Subscriber::whereEqual( 'email', $current_user->user_email )->whereEqual( 'status', 'subscribed' )->findArray(); //If logged in user is not mailpoet subscriber if ( empty( $this->user_subscriber ) ) { $this->run_actions(); } elseif ( $this->user_subscriber[0]['source'] == 'wordpress_user' || $this->user_subscriber[0]['source'] == 'woocommerce_user' ) { $this->run_actions(); if ( 'yes' == $this->show_gdpr_unsub && 'yes' == $this->show_form && ! empty($this->user_subscriber[0]['confirmed_ip']) ) { add_action( 'woocommerce_' . $this->form_position, array( $this, 'show_unsubscribe_form' ) ); } } } else { $this->run_actions(); }//End if }//End of __construct /** * Run necessary hooks * Show unsubscribe form */ public function show_unsubscribe_form() { ?>

default_status = get_option( 'wc_' . $this->tab_slug . '_checkbox_status' ); //Get default checkbox status $this->multi_subscription = get_option( 'wc_' . $this->tab_slug . '_multi_subscription' ); // Display GDPR consent $this->show_gdpr_consent = get_option( 'wc_' . $this->tab_slug . '_show_gdpr_consent' ); // Privacy page $this->privacy_page = get_option( 'wp_page_for_privacy_policy' ); if ( ! empty( $this->privacy_page ) ) { $this->privacy_page = get_permalink( $this->privacy_page ); if ( ! empty( $this->privacy_page ) ) { $this->privacy_page = 'Privacy Policy'; } else { $this->privacy_page = '[privacy_policy]'; } } // GDPR Consent Text $this->gdpr_consent_text = get_option( 'wc_' . $this->tab_slug . '_gdpr_subscription_consent_text' ); //Subscription Lists selected $this->list_ids = get_option( 'wc_mailpoet_segment_list', [] ); //If tick the `Enable subscription` checkbox if ( 'yes' == $this->show_form ) { //Hook into the checkout page. Adds the subscription fields. add_action( 'woocommerce_' . $this->form_position, array( $this, 'checkout_page_form' ) ); } }//End of run_actions /** * Checkout page form */ public function checkout_page_form() { ?>
multi_subscription ) && ! empty( $this->list_ids ) ): ?>

_e( 'Subscribe to Newsletters' ); ?>

list_ids )->findArray(); if ( is_array( $sagments ) ): foreach ( $sagments as $sagment ): ?>

show_gdpr_consent == 'yes' ): ?>

privacy_page, $this->gdpr_consent_text ); ?>

_e( 'Subscribe to Newsletter' ); ?>

tab_slug . '_checkout_label' ); // Puts default label if not set in the settings. $subscribe_label = ! empty( $checkout_label ) ? $checkout_label : $this->__( 'Yes, please subscribe me to the newsletter.' ); ?>

show_gdpr_consent == 'yes' ): ?>

privacy_page, $this->gdpr_consent_text ); ?>