Forms API

Add items to the cart with custom forms

The request for more robust Ubercart add to cart forms comes up fairly regularly. People generally have in mind the sort of form that allows customers to specify quantities for a set of products and add them to the cart all at once. The request came up so often that I put a short explanation on how to accomplish this through a custom form into an FAQ post on Ubercart.org.

This article will walk through a very basic example of how you can use the Ubercart function uc_cart_add_item() in a custom form submit handler to add multiple items to the cart at once. This article assumes a basic knowledge of Drupal's Forms API. Code examples are from Drupal 6, but they are mostly applicable to Drupal 5 as well.

Ryan's picture
Ryan Szrama

Ryan got his start in web development through an online sales company based in Louisville, KY, his home of over 10 years. It was there that he nursed Ubercart through its infancy to its use on over 20,000 websites as the Project Lead and community face of the project. Ryan joined Commerce Guys in 2009 and continued to lead Ubercart until branching out into Drupal Commerce, a new initiative focusing on empowering users to build e-commerce sites with the best new features that Drupal 7 has to offer. He focuses most of his time developing the code base, growing the community of contributors to the project, and training new users online and at community events.

Syndicate content