You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Paypal支付页面展示购物车内的多个商品明细

PayPal购物车商品列表展示配置方案

你的判断是正确的,仅将cmd参数修改为_cart不足以实现多商品明细展示,还需要补充对应的购物车上传配置和多商品参数,具体修改方式如下:

核心修改点

  • 把cmd参数值从_xclick改为_cart,同时新增隐藏字段<input type="hidden" name="upload" value="1">,该参数用于告知PayPal当前提交的是自定义上传的购物车商品列表
  • 删除原有的全局item_name、amount、quantity字段,改为按索引为每个商品单独配置参数,规则为:
    • 第N个商品名称:item_name_N
    • 第N个商品单价:amount_N
    • 第N个商品购买数量:quantity_N
  • 不需要手动传总金额,PayPal会根据所有商品的单价*数量自动累加计算总金额

修正后的代码示例

假设你的购物车数据存储在数组$cart_items中,结构参考如下:

$cart_items = [
    [
        'name' => '桨板',
        'price' => 100, // 单个桨板单价
        'num' => 5
    ],
    [
        'name' => '冲浪T恤',
        'price' => 30, // 单件T恤单价
        'num' => 3
    ]
];

对应的表单代码:

<form name="frm_customer_detail" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
    <input type="hidden" name="business" value="sb-unhom7091284@business.example.com">
    <input type="hidden" name="currency_code" value="EUR">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    
    <?php foreach ($cart_items as $index => $item): ?>
        <?php $n = $index + 1; ?>
        <input type="hidden" name="item_name_<?php echo $n; ?>" value="<?php echo $item['name']; ?>">
        <input type="hidden" name="amount_<?php echo $n; ?>" value="<?php echo $item['price']; ?>">
        <input type="hidden" name="quantity_<?php echo $n; ?>" value="<?php echo $item['num']; ?>">
    <?php endforeach; ?>

    <input type="hidden" name="order" value="<?php echo $order;?>">
    <div>
        <input type="submit" class="btn-action"
                name="continue_payment" value="Continue Payment">
    </div>
</form>

内容的提问来源于stack exchange,提问作者Dário

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 16:54:00