/**
  * Output the settings
  */
 public function output()
 {
     global $woocommerce, $woocommerce_settings, $current_section, $current_tab;
     if (!current_user_can('manage_woocommerce')) {
         wp_die(__('You do not have sufficient permissions to access this page.', MAILPOET_WOOCOMMERCE_TEXT_DOMAIN));
     }
     do_action('woocommerce_mailpoet_settings_start');
     $mailpoet_settings = $this->get_settings();
     // Get current section
     $current_section = empty($_REQUEST['section']) ? 'general' : sanitize_text_field(urldecode($_REQUEST['section']));
     $current = $current_section ? '' : ' class="current"';
     // Creates each settings section.
     $mailpoet_section = apply_filters('woocommerce_mailpoet_settings_sections', array('general' => __('General', MAILPOET_WOOCOMMERCE_TEXT_DOMAIN), 'lists' => __('Lists', MAILPOET_WOOCOMMERCE_TEXT_DOMAIN)));
     foreach ($mailpoet_section as $section => $title) {
         $title = ucwords($title);
         $current = $section == $current_section ? ' class="current"' : '';
         $links[] = '<a href="' . add_query_arg('section', $section, admin_url('admin.php?page=woocommerce_settings&tab=mailpoet')) . '"' . $current . '>' . esc_html($title) . '</a>';
     }
     echo '<ul class="subsubsub"><li>' . implode('| </li><li>', $links) . '</li></ul><br class="clear" />';
     woocommerce_admin_fields($mailpoet_settings);
     if ($current_section == 'lists') {
         include_once MailPoet_WooCommerce_Add_on()->plugin_path() . '/includes/admin/settings/settings-newsletters.php';
         $mailpoet_list = mailpoet_lists();
         do_action('woocommerce_mailpoet_list_newsletters', $mailpoet_list);
     }
 }
 /**
  * Output the settings
  */
 public function output()
 {
     global $current_section;
     $settings = $this->get_settings();
     WC_Admin_Settings::output_fields($settings);
     if ($current_section == 'lists') {
         include_once MailPoet_WooCommerce_Add_on()->plugin_path() . '/includes/admin/settings/settings-newsletters.php';
         $mailpoet_list = mailpoet_lists();
         do_action('woocommerce_mailpoet_list_newsletters', $mailpoet_list);
     }
 }
/**
 * This displays a checkbox field on the checkout
 * page to allow the customer to subscribe to newsletters.
 *
 * If the admin has enabled the customer to select the newsletters
 * then display a checkbox for each list available.
 *
 * @since   1.0.0
 * @version 3.0.0
 * @filter  mailpoet_woocommerce_subscription_section_title
 * @uses    woocommerce_form_field()
 * @uses    mailpoet_lists()
 * @uses    is_user_logged_in()
 * @uses    get_user_meta()
 * @uses    get_current_user_id()
 */
function on_checkout_page()
{
    $enable_checkout = get_option('mailpoet_woocommerce_enable_checkout');
    // Is the add-on enabled?
    $customer_selects = get_option('mailpoet_woocommerce_customer_selects');
    // Multi-Subscriptions
    $checkbox_status = get_option('mailpoet_woocommerce_checkbox_status');
    // Checkbox Status
    $subscription_lists = get_option('mailpoet_woocommerce_subscribe_too');
    // Subscription Lists selected
    $field_value = $checkbox_status == 'checked' ? 1 : 0;
    // Field Value
    /**
     * If the add-on is enabled and at least one list has been
     * selected. Display the subscription fields on the
     * checkout page.
     */
    if ($enable_checkout == 'yes' && !empty($subscription_lists)) {
        // If the user is logged in and has already subscribed, don't show the subscription fields.
        if (is_user_logged_in() && get_user_meta(get_current_user_id(), '_mailpoet_wc_subscribed_to_newsletter', true)) {
            return false;
        }
        echo '<div id="mailpoet_subscription_section">';
        echo '<h3>' . apply_filters('mailpoet_woocommerce_subscription_section_title', __('Subscribe to Newsletter/s', 'mailpoet-woocommerce-add-on')) . '</h3>';
        // Customer can select more than one newsletter.
        if ($customer_selects == 'yes') {
            foreach (mailpoet_lists() as $key => $list) {
                $list_id = $list['list_id'];
                // List ID number
                $list_name = $list['name'];
                // List Name
                // Checks if the list was selected in the add-on settings before showing the checkbox field.
                if (in_array($list_id, $subscription_lists)) {
                    mailpoet_woocommerce_form_field('mailpoet_checkout_subscription', array('id' => 'list-' . $list_id, 'type' => 'multicheckbox', 'class' => array('mailpoet-checkout-class form-row-wide'), 'label' => htmlspecialchars(stripslashes($list_name)), 'status' => $checkbox_status), $list_id);
                }
            }
        } else {
            $checkout_label = get_option('mailpoet_woocommerce_checkout_label');
            // Subscribe Checkbox Label
            $checkout_label = !empty($checkout_label) ? $checkout_label : __('Yes, please subscribe me to the newsletter/s.', 'mailpoet-woocommerce-add-on');
            // Puts default label if not set in the settings.
            woocommerce_form_field('mailpoet_checkout_subscribe', array('type' => 'checkbox', 'class' => array('mailpoet-checkout-class form-row-wide'), 'label' => htmlspecialchars(stripslashes($checkout_label))), $field_value);
        }
        // END if $customer_selects
        echo '</div>';
    }
    // END if $enabled_checkout
}
        /**
         * Output MailPoet lists tables
         */
        public function output_lists()
        {
            global $current_section, $wpdb;
            ?>
		<h3><?php 
            _e('MailPoet Lists', 'mailpoet_paid_memberships_pro_add_on');
            ?>
</h3>
		<p><?php 
            _e('Here you can assign the customer to the lists you enable when they subscribe. Simply tick the lists you want your customers to subscribe to and press "Save Changes".', 'mailpoet_paid_memberships_pro_add_on');
            ?>
</p>
		<table class="widefat">
			<thead>
				<tr valign="top">
					<td class="forminp" colspan="2">
						<table class="mailpoet widefat" cellspacing="0">
							<thead>
								<tr>
									<th width="1%"><?php 
            _e('Enabled', 'mailpoet_paid_memberships_pro_add_on');
            ?>
</th>
									<th><?php 
            _e('Lists', 'mailpoet_paid_memberships_pro_add_on');
            ?>
</th>
								</tr>
							</thead>
							<tbody>
							<?php 
            $checkout_lists = get_option('mailpoet_paid_memberships_pro_subscribe_too');
            foreach (mailpoet_lists() as $key => $list) {
                $list_id = $list['list_id'];
                $checked = '';
                if (isset($checkout_lists) && !empty($checkout_lists)) {
                    if (in_array($list_id, $checkout_lists)) {
                        $checked = ' checked="checked"';
                    }
                }
                echo '<tr>
									<td width="1%" class="checkbox">
										<input type="checkbox" name="checkout_lists[]" value="' . esc_attr($list_id) . '"' . $checked . ' />
									</td>
									<td>
										<p><strong>' . $list['name'] . '</strong></p>
									</td>
								</tr>';
            }
            ?>
							</tbody>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
		<?php 
        }
 /**
  * Output the settings
  *
  * @since   1.0.0
  * @access  public
  * @global  $current_section
  * @uses    woocommerce_admin_fields()
  * @uses    self::get_settings()
  * @uses    wp_enqueue_script()
  * @version 3.0.0
  */
 public function output()
 {
     global $current_section;
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     wp_enqueue_script('mailpoet_woocommerce_settings', MAILPOET_WOOCOMMERCE_URL_PATH . '/assets/js/admin/settings' . $suffix . '.js', array('jquery', 'select2'), MAILPOET_WOOCOMMERCE_VERSION, true);
     wp_localize_script('mailpoet_woocommerce_settings', 'mailpoet_wc_admin_params', array('i18n_nav_warning' => __('The changes you made will be lost if you navigate away from this page.', 'mailpoet-woocommerce-add-on')));
     woocommerce_admin_fields(self::get_settings($current_section));
     if ($current_section == 'lists') {
         include_once 'settings/mailpoet-lists.php';
         $mailpoet_list = mailpoet_lists();
         do_action('woocommerce_mailpoet_list_newsletters', $mailpoet_list);
     }
     wp_nonce_field('mailpoet_wc_settings', '_mailpoet_wc_nonce', false);
 }