Criei um item de linha usando hook_uc_line_item () e adicionei o item de linha no hook_uc_order ().
Os produtos finais se parecem com:
/*
* Implement hook_uc_line_item()
*/
function my_module_uc_line_item() {
$items[] = array(
'id' => 'handling_fee',
'title' => t('Handling Fee'),
'weight' => 5,
'stored' => TRUE,
'calculated' => TRUE,
'display_only' => FALSE,
);
return $items;
}
/**
* Implement hook_uc_order()
*/
function my_module_uc_order($op, $order, $arg2) {
// This is the handling fee. Add only if the user is a professional and there
// are shippable products in the cart.
if ($op == 'save') {
global $user;
if (in_array('professional', array_values($user->roles))) {
// Determine if the fee is needed. If their are shippable items in the cart.
$needs_fee = FALSE;
foreach ($order->products as $pid => $product) {
if ($product->shippable) {
$needs_fee = TRUE;
}
}
$line_items = uc_order_load_line_items($order);
// Determine if the fee has already been applied.
$has_fee = FALSE;
foreach ($line_items as $key => $line_item) {
if ($line_item['type'] == 'handling_fee') {
$has_fee = $line_item['line_item_id'];
}
}
// If the cart does not already have the fee and their are shippable items
// add them.
if ($has_fee === FALSE && $needs_fee) {
uc_order_line_item_add($order->order_id, 'handling_fee', "Handling Fee", 9.95 , 5, null);
}
// If it has a fee and does not need one delete the fee line item.
elseif ($has_fee !== FALSE && !$needs_fee) {
uc_order_delete_line_item($has_fee);
}
}
}
}