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

如何在含price_data的Stripe PHP Checkout Session中指定Locale?

在Stripe Checkout Session中指定Locale的方法

直接在创建Checkout Session的配置数组里添加locale字段,传入对应的语言代码就能指定结账页面的显示语言。

修改后的代码示例

$checkout_session = \Stripe\Checkout\Session::create([
        'line_items' => [[
            'price_data' => [
                'currency' => 'eur',
                'product_data' => [
                  'name' => 'prenotazione',
                ],
                'unit_amount' => $amount*100,
              ],
              'quantity' => 1,
        ]],
        'mode' => 'payment',
        'payment_intent_data' => [
            'metadata' => ["cart_id"=>$cart_id]
          ],
        'success_url' => $YOUR_DOMAIN . '/mybookings?message=newBkgCreated&cart_id='.$cart_id,
        'cancel_url' => $YOUR_DOMAIN . '/checkout?message=payment_cancelled&cart_id='.$cart_id,
        'automatic_tax' => [
          'enabled' => true,
        ],
        // 添加Locale参数指定语言
        'locale' => 'zh', // 简体中文,可替换为其他支持的语言代码,比如'it'对应意大利语
      ]);
    header("HTTP/1.1 303 See Other");
    header("Location: " . $checkout_session->url);

补充说明

  • Stripe支持多种语言代码,常见的有zh(简体中文)、en(英文)、it(意大利语)、fr(法语)等,按需替换即可。
  • 设置后,Stripe结账页面的按钮、提示文本等内容都会自动切换为对应语言。

内容的提问来源于stack exchange,提问作者FaustoDassenno

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:55:35