Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: [Assigned] Cred commerce with free product

$
0
0

Hi Pat,

please test this code:

add_action('cred_commerce_after_payment_completed','affectation_membre');
function affectation_membre($data){
	$cred_form_id = $data['extra_data']['cred_form_id'];
	if ($cred_form_id == 279){
		$cred_post_id = $data['extra_data']['cred_post_id'];
		$user_id = get_post_meta( $cred_post_id, 'wpcf-utilisateur-id');
		$annee = get_the_time('Y'); // définition de l'année en cours ou année suivante si après le 1° décembre
		// définition de la classe de membre
		switch (get_post_meta($cred_post_id, 'wpcf-classe-de-membre', true)) {
			case '92':
				$classe_membre = 'BIENFAITEUR';
				break;
			case '90':
				$classe_membre = 'ACTIF';
				break;
			case '91':
				$classe_membre = 'ELEVEUR';
				break;
			default:
				$classe_membre = '';
				break;
		}
		$groups = 2;
		Groups_User_Group::create(array( 'user_id' => $user_id, 'group_id' => $groups ) ); // le souscripteur devient membre
		update_user_meta( $user_id, 'wpcf-type-de-membre', $classe_membre ); // définition du type de membre
		update_user_meta( $user_id, 'wpcf-annee', $annee ); // définition de l'année d'abonnement
		update_user_meta( $user_id, 'wpcf-annee-dabonnement', $annee ); // définition de l'année d'abonnement
	}
}

I've corrected the variables to obtain the ID of CRED Commerce form that customer used, also changed or if elseif to be a switch with a default value.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Ana


Viewing all articles
Browse latest Browse all 20145

Trending Articles