Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am looking for sample code to programmatically add to the Cart using for instance uc_cart_add_item where the price is needing to be set custom.
From what I understand;
uc_cart_add_item($nid, $qty, $data)
where $data is an arbitrary array of attributes.
What is the mapping within $data to alter the sell price of the item?
Comments
Comment #1
longwaveThere is no way of setting a price directly using $data, but you can set $data['attributes'] to force a particular set of attribute options.
If this is not what you need, you can implement hook_uc_product_alter() to change the product price; maybe the simplest way is to set $data['price'] and then set
$node->price = $node->data['price']
in your hook implementation