如何在 woocommerce 中跳过结帐并将用户直接重定向到付款页面?

问题描述 投票:0回答:1

我正在寻找有关如何在 woocommerce 中实施以下支付机制的答案:

我们知道产品id,用户已经登录,用户的所有信息都已经知道,设置了唯一的一个结账网关,所以不需要在结账页面。如何跳过?

那么,在我的情况下付款应该如何进行:

在后端的某个位置生成订单,其中包含所有需要的信息,之后当用户单击“支付订单”按钮时,他应该直接重定向到付款页面,而无需结账页面。

根据我的研究,找到了

WC_Order::get_checkout_payment_url()
方法,但它只能提供结帐页面的链接,但我确切需要付款页面,用户可以在其中输入凭据,即银行卡号、CVC。当然,我可以向 url 添加额外的 GET 参数,例如“skip-ckeckout”,并且如果仅指定此 GET 参数,则在 ckeckout 页面上触发单击“pay”按钮。但我认为这不是一个好的解决方案。

我还想将 ckeckout 页面内容与 display: none 进行“集成”,并自动填写我需要获取付款按钮的所有输入。这个解决方案看起来很奇怪。

我怎样才能使所描述的机制发挥作用而不产生任何奇怪的ACRION?在这种情况下,哪种解决方案更适合我?

抱歉,如果这个问题很愚蠢,但是通过互联网进行了数小时的研究仍然没有给出预期的结果

谢谢❤️!

php wordpress woocommerce payment
1个回答
0
投票

有一个很酷的主意给你。我曾经做过这样的事情,我直接将用户发送到付款页面,跳过了通常的环节。让我们做一些类似的事情,受到亚马逊一键购买按钮的启发。

计划是这样的:

  1. 收集账单详细信息:当人们注册时或注册后,获取他们的账单信息。也许可以给他们折扣或其他东西来让交易更顺利。

  2. 个人资料页面魔法:在用户个人资料中添加基本的计费字段。 ACF 插件是你的朋友。

  3. 智能卡存储:不要在您的网站上保存卡信息。太冒险了!相反,让 Stripe 将其变成安全令牌。您稍后可以使用此令牌进行计费,而无需透露实际的卡信息。

  4. 快速购物车到结账:当有人将产品添加到购物车时,将他们带到结账处。自动填写他们保存的信息。

  5. Stripe 集成:不再有老式结账方式。只需使用 Stripe 代币即可一键计费。

快速入门: 获取 Stripe PHP SDK。您可以使用 Composer,也可以直接下载并将其包含在您的项目中。相信我,这只是小菜一碟。

标记卡详细信息

\Stripe\Stripe::setApiKey('YOUR_STRIPE_SECRET_KEY');

// Create a new customer and store their card
$customer = \Stripe\Customer::create([
    'email' => $user_email, // Get this from the user's profile
    'source' => $token // This is the tokenized card details from Stripe.js
]);

// Save the customer ID to user's meta
update_user_meta($user_id, 'stripe_customer_id', $customer->id);

一键购买

\Stripe\Stripe::setApiKey('YOUR_STRIPE_SECRET_KEY');

$customer_id = get_user_meta($user_id, 'stripe_customer_id', true);

// Charge the customer
$charge = \Stripe\Charge::create([
    'amount' => $amount, // Convert to cents and get this from the cart total
    'currency' => 'usd', // Your currency
    'customer' => $customer_id, // Use the customer ID saved earlier
]);

// Check if the charge was successful
if($charge->status == 'succeeded') {
    // Redirect to success page
} else {
    // Handle payment error
}

我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.