I looked everywhere and couldn't find the appropriate and clear explanation of how to change the price of a line item. I have a line item called "fee", the fee changes based on the date and zipcode. I have a function that returns the correct fee based on the parameters. Now what hook do I call to update the "fee" line item? This is what I found

function ck_custom_commerce_cart_order_refresh($order_wrapper)
$fee = _ck_custom_delivery_fee($order);//this function returns an integer

foreach ($order_wrapper->commerce_line_items as $line_item_wrapper)
        //I would like to update the fee 

Please what is the right of way of accomplishing this? FYI: I'm using the commerce fees module if that helps.


You want to change the price components of the line item you're wanting to update. You can use rules for this, but since you're writing a hook, you can just call the function that Rules would use:

commerce_line_item_unit_price_amount($line_item, $amount, $component_name, $round_mode);

For example, if you want to change it to $5.00:

commerce_line_item_unit_price_amount($line_item, 500, 'base', COMMERCE_ROUND_HALF_DOWN);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.