Closed Januszpl closed 8 years ago
@Wysija What do you guys think of this?
I changed on_checkout_page function in mailpoet-woocommerce-addon.php
function on_checkout_page($checkout){ // Checks if subscribe on checkout is enabled. $enable_checkout = get_option('mailpoet_woocommerce_enable_checkout'); $checkout_label = get_option('mailpoet_woocommerce_checkout_label');
// modified
// if user logged check if his email is already in newsletter database
if (is_user_logged_in() ) {
$user_id = get_current_user_id();
$user_email = get_user_meta( $user_id, 'billing_email', true );
global $wpdb;
// look up for email in wp_3_wysija_user
$added = $wpdb->query("SELECT * FROM wp_3_wysija_user WHERE email LIKE '$dodany_email' AND status = '1' ;");
$il=count($added);
} else {
$added=0;
// if not logged it would be great to check via JS/PHP after user filled email to check if he has been already a subscriber - if not then show checkbox field or if yes then hide checkbox field
}
// added extra condition && $added!=1 to show field only for new subscribers
if(($enable_checkout == 'yes') && ($added!=1)){
echo '<div id="mailpoet_checkout_field">';
//echo apply_filters('mailpoet_woocommerce_subscribe_checkout_title', '<h3>'.__('Subscribe to Newsletter', 'mailpoet_woocommerce').'</h3>');
woocommerce_form_field('mailpoet_checkout_subscribe', array(
'type' => 'checkbox',
'class' => array('mailpoet-checkout-class form-row-wide'),
'label' => htmlspecialchars(stripslashes($checkout_label)),
), $checkout->get_value('mailpoet_checkout_subscribe'));
echo '</div>';
}
}
It would be great to hide checkbox field when logged user visit checkout page and he is aleardy a subscriber.
For non logged user it would great if after filling e-mail it would check if it is already in newsletter database. If not then it would show checkbox field to sing up for newsletter.