So I have a product named "Store Credit" which is added to the cart when the user wishes to use points to get discount. The discount is always different depending on how many points the user enters. If the user enters 500 points, I want to create a line item with a price of -500$.

function switch_addtocart_cart_line_item_refresh($line_item, $order){

    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
    $line_item_wrapper->commerce_unit_price->amount = 150;


My dpm indicates the price has changed but the price in my cart and order review page is still the same? What am I doing wrong.


2 Answers 2


Check your hook_name, I think thats the issue.

Default commerce hook is mentioned below.

hook_commerce_cart_line_item_refresh($line_item, $order_wrapper)

So, Your hook can be like (assuming switch_addtocart is your module name)

function switch_addtocart_commerce_cart_line_item_refresh($line_item, $order_wrapper) {


Please check and let us know.


You also need to change.

  • 1
    please include the original line of code in an answer like this so that the answer can easily be referenced back to the question - as it stands, I think I know what you're saying, but that's a guess. Try something like "instead of this {code}, try this {code}"
    – Geoff
    May 12, 2015 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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