I am selling membership type without using subscription module as it doesn't fit into my scenario. I am assiging role by help of rules as per Randy screencast & it works nice for me.

Now the problem is with renewal of the membership. So I have to set up another kind of product type, which will work for renewing the membership.

So is there any way to restrict usertype to buy any product type ?

Thanks :)


You can create a different product display type (i.e. content type) for the renewal product (at admin/structure/types). Then you can restrict that content type to those with the members role (in admin/people/permissions).

Or, if you want to show the product display type, but restrict the actual purchase, I think you have to resort to custom code like this:

 * Implements hook_form_FORM_ID_alter().
 * Alter the Commerce 'Add to Cart' form.
function custom_module_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {
  global $user;
  $roles_allowed_to_buy = array(
    'Some Custom Member Role',
  if (!array_intersect($user->roles, $roles_allowed_to_buy)) {
    // Display a help message.
    $form['help'] = array(
      '#markup' => t('You do not have permission to buy this product.'),
    // Disable the whole form.
    $form['#disabled'] = TRUE;
    // Remove any submit button(s).

(that's an example you would put inside a module called custom_module)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.