0

I want to add a custom text field on the product details page; its value will be shown on the cart and checkout pages. I have added the text field on the product, but it's not saved. What am I missing in the following code?

function my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'uc_product_add_to_cart_form_2') {
    $form['additional_guests'] = array(
      '#type' => 'textfield',
      '#title' => t("Additional Guest Names"),          
    );
  }
}

How can I save this custom field and retrieve its value on the cart/checkout page?

1
  • Use Attributes and set up a Textfield attribute on your product.
    – anonymous
    Jun 21, 2019 at 19:09

1 Answer 1

0

The uc_attributes module, which has been part of Ubercart for 12 years, was specifically designed to handle this situation.

Enable the uc_attributes module. Edit your product, then go to the "Attributes" tab and add a "textfield" type attribute to your product. Your customer will then be able to add text to the purchased product. This textfield will be displayed in the cart, on the checkout page, on the review order page, and in the admin/user view of the completed order.

In short, the correct way to do this is to "Use Attributes and set up a Textfield attribute on your product" as I stated in my previous answer (which was erroneously turned into a "comment" by some unknown user).

The Ubercart project page at https://www.drupal.org/project/ubercart gives links to detailed information about how to do this. Specifically, see: https://www.drupal.org/docs/7/modules/ubercart/all-about-products/product-attributes-and-options and the video tutorial at https://www.youtube.com/watch?v=fVDOqI7Gge4

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.