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

修改代码实现Stripe SOFORT/SEPA订单自动从待处理转处理中

Solution: Modify the Code to Cover SOFORT & SEPA, and Skip Subscription Restriction

Got it, let's adjust your existing code to meet your needs—we'll remove the subscription-only limitation, add support for SOFORT payments, and make sure orders move straight to processing (which maps to your "in progress" state) instead of waiting for Stripe's validation.

Here's the revised code with explanations of the key changes:

add_action( 'wc_gateway_stripe_process_response', 'action_wc_gateway_stripe_auto_process_sofort_sepa_orders', 0, 2);
function action_wc_gateway_stripe_auto_process_sofort_sepa_orders ($response, $order) {
    // Check if Stripe response is pending, and payment method is SEPA Debit or SOFORT
    if( $response->status === 'pending' && in_array( $response->source->type, ['sepa_debit', 'sofort'] ) ) {
        // Update order status to "processing" (your "in progress" state)
        $order->update_status('processing');
        
        // Add a clear order note for reference
        $order->add_order_note( sprintf( __( 'Order automatically moved to processing by custom hook (Stripe Charge ID: %s) — awaiting Stripe payment validation.', 'woocommerce-gateway-stripe' ), $response->id ) );
        
        // Save the order changes
        if ( is_callable( array( $order, 'save' ) ) ) {
            $order->save();
        }
    }
}

Key Changes I Made:

  1. Removed Subscription Restrictions: The original code was locked to subscription orders only. I stripped out all subscription-specific checks so this works for every order using SEPA or SOFORT.
  2. Added SOFORT Support: Stripe tags SOFORT payments with the source type sofort, so I added it to the payment method check alongside sepa_debit.
  3. Changed Status to Processing: Instead of payment_complete() (which marks orders as "completed"), I used update_status('processing') to match your "in progress" requirement. This keeps the order in your active workflow while skipping the on-hold wait.
  4. Updated Order Note: The note now clearly states the order was moved to processing and mentions it’s still waiting on Stripe’s validation—helpful for your team’s record-keeping.

Quick Tips:

  • Hook Priority: The priority is set to 0 so this runs early, before any other Stripe-related status updates that might override it.
  • Testing: Test this with Stripe’s SEPA and SOFORT test payment methods first to confirm it behaves as expected.
  • Webhooks: If you use Stripe webhooks, double-check they don’t revert the order status later. You may need to adjust webhook handling if they try to set orders back to on-hold.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 21:18:11