add rgpd checkbox to mailpoet 2 code example

Example: mailpoet 3 rgpd

function mgris_subscription_checkbox() {
// changer cette variable en fonction de l'id de votre liste
	$nl_list_id = 4;

	if(!is_user_logged_in()) {
		echo '<p>';
		_e('<span>Recevez toute l\'année les offres promotionnelles en vous inscrivant à notre newsletter</span><br />','textdomain');
		_e('<label for="subscription-box">S\'inscrire à notre newsletter</label>', 'textdomain');
		echo '<input id="subscription-box" type="checkbox"name="subscribe_newsletter" value="'.$nl_list_id.'" />';
		echo '</p>';
	}
}

add_action('woocommerce_checkout_after_customer_details', 'mgris_subscription_checkbox');

function mgris_subscription_newsletter_checkout() {
// changer cette variable en fonction de l'id de votre liste
	$listID = array(4);

	$subscrib = $_POST['subscribe_newsletter'] ;
	$email = $_POST['billing_email'];

	if(!empty($subscrib) && !empty($email)) {
		$userData=array(
			'email' => $email,
			'firstname' => $_POST['billing_first_name'],
			'lastname' => $_POST['billing_last_name']
		);

		$data=array(
			'user' => $userData,
			'user_list' => array( 'list_ids'=> $listID )
		);

		$userHelper=&WYSIJA::get('user','helper');
		$userHelper->addSubscriber($data);
	}
}

add_action('init','mgris_subscription_newsletter_checkout');

Tags:

Misc Example