Drupal Ubercart hook after complete purchase order object saved.

Ubercart is the best and highly used e-commerce framework for Drupal. Ubercart provides awesome hook functionality. Using hook we can able to change some functionality without touching or modify the Ubercart code file.

If we want to change or update our database after complete order purchase on Ubercart we can be using the hook. Like we want to change the user role after user purchase any product from the site. We can change the user role using hook after the user successfully purchase any product from the site.

Let’s see how we change the user role to the premium user after complete the purchase using the hook.

function thecodingstuff_uc_checkout_complete($order, $account) {

    $productRole = "Premium Member";

    $uid = $account->uid;

    $role = user_role_load_by_name($productRole);
    user_multiple_role_edit(array($account->uid), 'add_role', $role->rid);        

}

the “uc_checkout_complete” hook called when any user completes the product purchase process.

So when this hook called we change the user role to “Premium Member”.

If you face any issue after using above code write the comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s