Use hook_form_alter and
'#access' => !is_anonymous
under add to cart submit
If the default add to cart form lacks some necessary functionality, you can either use a form alter hook or consider this cleaner approach:
Extend commerce_cart\Form\AddToCartForm.php
/**
* Implements hook_entity_type_build().
*/
function mymodule_entity_type_build(array &$entity_types) {
$entity_types['commerce_order_item']->setFormClass('add_to_cart', '\Drupal\mymodule\Form\AddToCartForm');
}
hook_module_implements_alter()
. Or you can use the module_set_weight
API function (implemented in core\includes\module.inc).You can use hook_preprocess_commerce_product as in:
function mymodule_preprocess_commerce_product(&$variables) {
$product = $variables['elements']['#commerce_product'];
...
}
Found errors? Think you can improve this documentation?
edit this page