How to hide 'add to cart' button, on full mode view of a specific content type? It has to be done on condition if product is purchased for this content type.

I tried to add custom field template but for add to cart button could not find the right template name. I also found out the field name which displays add to cart "field-product-ref" but the template field--field-product-ref.tpl.php is not working. Need help in either identifying correct template name or any other approach which is correct?

  • Are you using ubercart or ?
    – Rupesh
    Commented May 18, 2014 at 18:17
  • drupal commerce on D7
    – dalveer
    Commented May 18, 2014 at 18:42
  • Hiding the add to cart form is easy (e.g hide in "Manage Display"), the hard part will be determining if the current user has bought a product referenced on that product display and hiding it dynamically. Commented May 19, 2014 at 1:55
  • yes I agree... for "hard part" now I am exploring making use of "<themeName>_theme_form_alter". And awaiting sound advices.
    – dalveer
    Commented May 19, 2014 at 2:59
  • There is some information on this in drupal.org/node/1266132 where you implement hook_form_alter for the add to cart form. Commented May 19, 2014 at 10:57

2 Answers 2


You could use devel_themer module. After enable the module, a checkbox appear on left bottom of the window then, select the checkbox now you could find the template name after click the add to cart button...


I manage to resolve it.
Now sharing back with the community.

To hide the add-to-cart button on FULL view mode if product is purchased

 1. Implement this solution in _theme_form_alter.
 2. Sql query to check if product id belongs to complete order list for particular user
     "$query = db_select('commerce_order', 'cord');
    $query->join('commerce_line_item', 'li', 'cord.order_id = li.order_id');
    $query->join('field_data_commerce_product', 'prod', 'li.line_item_id = prod.entity_id');
    $query->condition('cord.uid', $user->uid, '=')
          ->condition('cord.status', 'completed', '=')
          ->condition('commerce_product_product_id ',$prod_id,'=')
          ->fields('prod', array('commerce_product_product_id'));
    $result = $query->execute();
    $resultValue = $result->fetchColumn(0);"
 3. Hide add-to-cart button if product id matches query result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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