1
Answers
Vote up!
0
Vote down!

How do I Conditionally display Add To Cart form?

I want to have the Add To Cart form only display in a product-display node after comparing against a text field....I've tried the 'Conditional Fields' module but it doesn't work and the Field conditional state module but it doesn't display the text field that is needed as a control....I've also seen a 'Sandboxed' project by Haza but I lack coding skills and I'm nervous about using something that warns to be careful!
Does anyone know of anything else that is worth checking out?

Asked by: athomson
on January 21, 2014

1 Answer

Vote up!
0
Vote down!

I did something like this:

function HOOK_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {
if (!empty($form_state['context']['entity_id'])) {
$nid = $form_state['context']['entity_id'];

$special = db_query('SELECT field_product_special_value FROM {field_data_field_product_special} WHERE entity_id = :nid', array(':nid' => $nid))->fetchField();
if ($special) {
unset($form['submit']);
unset($form['quantity']);
}
}
}

Not sure if this is the best way but it works.

Answer by: falc0
Posted: May 14, 2014