1

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 May 18 '14 at 18:17
  • drupal commerce on D7 – dalveer May 18 '14 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. – David Thomas May 19 '14 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 May 19 '14 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. – Pontus Nilsson May 19 '14 at 10:57
0

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...

0

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, privacy policy and cookie policy

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