MemberPress: Snippets

Set Contact opt-in status and consent

<?php
add_action( 'mepr-account-is-active', 'set_contact_optin_status_and_consent', 11 );

/**
 * When a member becomes active in MemberPress change their opt-in status to confirmed and set their consents
 * 
 * @param $txn
 *
 * @return void
 */
function set_optin_status_and_consent( $txn ) {
	$contact = \GroundhoggMemberPress\Plugin::instance()->event_handler->get_contact_from_txn( $txn );
	
	// Change to confirmed
	$contact->change_marketing_preference( \Groundhogg\Preferences::CONFIRMED );
	
	// Update their consents
	$contact->set_marketing_consent();
	$contact->set_gdpr_consent();
	$contact->set_terms_agreement();
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us