Limit total quantity of products across user's entire order history I am trying to limit a user's total quantity of products across their entire order/purchase history based on a field on that product. For example, if Can of Peanuts has a limit of 3 per user, then the user should not be able to buy 3 then place another order for 3.

Does anyone have any recommendations for ways to accomplish this?
Use hook_form_commerce_cart_add_to_cart_form_alter()

&lt;?php 
mymodule_form_commerce_cart_add_to_cart_form_alter(&amp;$form, &amp;$form_state, $form_id)
{ 
  /*code*/ 
}
?&gt;


Then, inside the hook, use entityFieldQuery to get list of orders for this user

For locating the "currently selected product," you can use the form_state variable:

&lt;?php 
$current_product = $form_state['default_product']; 
?&gt;


Finally, you'll want to iterate over each order and use entity meta data wrappers to wrap the orders so you can iterate over the line items, looking for matching products.

&lt;?php
foreach ($orders as $order_id =&gt; $order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  foreach ($order_wrapper-&gt;commerce_line_items as $delta =&gt; $line_item_wrapper) {
    $line_item = $line_item_wrapper-&gt;value();
  }
}
?&gt;


The final final round would include looking to see if the line item is attached to the product and then counting the number of products this person has purchased.

Unfortunately, while you might be able to construct an SQL statement that does most of the heavy lifting (instead of iterating over all the user's orders and line items), it would require much more intimate knowledge of your particular store architecture.