希望这个答案对您来说还不算太晚,但是您是否尝试过以下方法:
$order->line_items[] = uc_order_line_item_add($order->order_id, 'Pay at door','Pay at door',5);
问题是 uc_order_line_item_add 只是更新数据库而不是当前传递的订单对象,后来用于计算总计等,幸运的是 uc_order_line_item_add 返回一个可以简单地附加到订单对象的行项目数组。我不确定它是否可以在您的付款方式中使用,但它在 hook_uc_order 中对我有用,在那里我遇到了类似的税收问题,直到第二次刷新才更新。
如果它有助于我的完整示例代码如下:
<?php
function my_module_uc_order($op, &$order, $arg2) {
switch ($op) {
case 'presave':
// using presave as taxes are calculated during save
$line_item_id = FALSE;
if (!is_array($order->line_items)) {
$order->line_items = array();
}
else {
foreach ($order->line_items as $index => $line_item) {
if ($line_item['type'] == 'my_line_item') {
$line_item_id = $line_item['line_item_id'];
break;
}
}
}
if ($line_item_id === FALSE) {
// Add item.
// Dummy amount for testing.
$amount = 3;
// uc_order_line_item_add returns a line_item array so we can just add it to the order object.
$order->line_items[] = uc_order_line_item_add($order->order_id, 'my_line_item', 'My Item Title (added)', $amount);
// uc_order_line_item_add($order_id, $type, $title, $amount, $weight = NULL, $data = NULL).
}
else {
// Update item.
// Dummy amount for testing.
$amount = 4;
// uc_order_update_line_item($id, $title, $amount, $data = NULL).
uc_order_update_line_item($line_item_id, 'My Item Title (updated)', $amount);
// Manually modify amount.
$order->line_items[$index]['amount'] = $amount;
}
break;
}
}
/**
* Implements hook_uc_line_item().
*/
function my_module_uc_line_item() {
$items[] = array(
'id' => 'my_line_item',
'title' => t('Custom text'),
'weight' => 0,
'default' => FALSE,
'stored' => TRUE,
'add_list' => TRUE,
'calculated' => TRUE,
);
return $items;
}