Cash on delivery extra fee I use cash on delivery payment method. When the user select this payment method an extra fee should be added to the order total. NOT to the product line items. Any ideas? I read i a post that a workaround for that is to add a custom line item and charge it the extra fee. Anyway I didn't understand how i should that

I put this code to my custom rule action in order to add a price component via a line item. The problem is it throws an error when i finally save the order in the last line. The error is:

Warning: Invalid argument supplied for foreach() in commerce_price_components_combine() (line 972 of /Users/Sakis/Sites/Under_Construction/e-wireless/profiles/commerce_kickstart/modules/commerce/modules/price/commerce_price.module).

$default_currency_code = commerce_default_currency();
if ($balance = commerce_payment_order_balance($order)) {
   $default_currency_code = $balance['currency_code'];
}
$line_item = commerce_line_item_new('cod_fee', $order-&gt;order_id);
dsm($line_item,'line_item');
// Wrap the line item and order to simplify manipulating their field data.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);

$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item); 
$line_item_wrapper-&gt;line_item_label = 'Αντικαταβολή';
$line_item_wrapper-&gt;quantity = 1;
$line_item_wrapper-&gt;commerce_unit_price-&gt;amount = '200';
$line_item_wrapper-&gt;commerce_unit_price-&gt;currency_code = $default_currency_code;
$line_item_wrapper-&gt;commerce_unit_price-&gt;data = commerce_price_component_add(
    $line_item_wrapper-&gt;commerce_unit_price-&gt;value(),
    'cod_fee',
    $line_item_wrapper-&gt;commerce_unit_price-&gt;value(),
    TRUE,
    FALSE
);
commerce_line_item_save($line_item);
// Add it to the order's line item reference value.
$order_wrapper-&gt;commerce_line_items[] = $line_item;

// Save the order.
$order_wrapper-&gt;save();
If you create the COD payment method yourself you can in the code that would normally process payments ect. add the fee to the order by adding a line item to the order. You could use a custom price formatter instead of showing the line item.

I have answered how add a line item in code here.