1 reply [Last post]
Skrealin's picture
Offline
Joined: 08/29/2008
Juice: 11
Was this information Helpful?

Is there a way to hide the quantity field generated by the uc_product_add_to_cart_form() function on teasers?
I'd like to have an "Add to Cart" button but only want to show the quantity field on the product page.

I've tried putting an IF statement around the section that I think generates the quantity field, but am not sure what variable I should be checking to find out if I'm looking at a teaser.

I've tried $teaser, $page == 0, $node->teaser and probably others but none seem to work...

function uc_product_add_to_cart_form($node) {
  $form = array();
  $form['#base'] = 'uc_product_add_to_cart_form';
  $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
  if ($node->default_qty > 0 && variable_get('uc_product_add_to_cart_qty', false)) {
    $form['qty'] = array('#type' => 'textfield',
      '#title' => t('Quantity'),
      '#default_value' => $node->default_qty,
      '#size' => 5,
      '#maxlength' => 6,
    );
  }
  else {
    $form['qty'] = array('#type' => 'hidden', '#value' => 1);
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' =>  variable_get('uc_product_add_to_cart_text', t('Add to cart')),
    '#id' => 'edit-submit-'. $node->nid,
    '#attributes' => array(
      'class' => 'node-add-to-cart',
    ),
  );
  return $form;
}
Skrealin's picture
Offline
Joined: 08/29/2008
Juice: 11
Re: Hiding Quantity field on teasers

Has anyone tried to do this before? I can't figure out why its not working, all I can think is that the $teaser variable is not being made available to the module somehow?