首页 > 解决方案 > WooCommerce 支付网关(全部)错误 - 类 wc-form-handler

问题描述

我可以让页面显示表单并拥有所有相关(我知道的)信息,但是提交时出现内部服务器错误,就好像我错过了一步!

根据最终客户的要求,我已将付款阶段分成 4 页。付款方式如下。网关是:

  1. 默认贝宝网关
  2. Stripe 官方网关

错误是({site} = 实际站点正常存在):

2019-02-23T14:04:10+00:00 严重未捕获的错误:调用 /var/www/vhosts/{site}/wp-content/plugins/woocommerce/includes/class 中布尔值的成员函数 get_id() -wc-form-handler.php:360 堆栈跟踪:#0 /var/www/vhosts/{site}/wp-includes/class-wp-hook.php(286):WC_Form_Handler::pay_action(Object(WP) ) #1 /var/www/vhosts/{site}/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #2 /var/www/vhosts/{site} /wp-includes/plugin.php(531): WP_Hook->do_action(Array) #3 /var/www/vhosts/{site}/wp-includes/class-wp.php(750): do_action_ref_array('wp' , 数组) #4 /var/www/vhosts/{site}/wp-includes/functions.php(1105): WP->main('') #5 /var/www/vhosts/{site}/wp- blog-header.php(16): wp() #6 /var/www/vhosts/{site}/index.php(17): require('/var/www/vhosts...') #7 {main} 在第 360 行抛出 /var/www/vhosts/{site}/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php

<?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?>
<?php
    if ( ! is_ajax() ) {
        do_action( 'woocommerce_review_order_before_payment' );
    }
?>
<?php
    $gateways = WC()->payment_gateways->get_available_payment_gateways();
    $enabled_gateways = [];
    if( $gateways ) {
        foreach( $gateways as $gateway ) {
            if( $gateway->enabled == 'yes' ) {
                $enabled_gateways[] = $gateway;
            }
        }
    }
?>
<div class="payment-methods">
    <ul>
        <?php 
            foreach($enabled_gateways as $get_gateway){
                echo '<li>Pay with '.$get_gateway->title.'<div class="btn-group"><a href="#payment" class="button" onclick="loadMethod('.str_replace(' ', '_', $get_gateway->title).')">Pay by '.str_replace('Stripe', 'Card', $get_gateway->method_title).'</a></div>'; 
            } 
        ?>
    </ul>
</div>
<div class="payment-container" id="payment">
    <div class="checkout">
        <?php foreach($enabled_gateways as $get_gateway): ?>
        <?php #if($get_gateway->title != "PayPal"): ?>
                <form name="checkout" method="post" class="checkout1" action="<?php echo esc_url( $get_checkout_url ); ?>" enctype="multipart/form-data">
                <?php #wp_nonce_field( 'stripe' ); ?>
                <input id="payment_method_<?php echo esc_attr( $get_gateway->id ); ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr( $get_gateway->id ); ?>" <?php checked( $get_gateway->chosen, true ); ?> data-order_button_text="<?php echo esc_attr( $get_gateway->order_button_text ); ?>" />
                <input type="hidden" name="woocommerce_pay" value="1" />
                <?php $get_gateway->payment_fields(); ?>
                <?php wc_get_template( 'checkout/terms.php' ); ?>

                <?php do_action( 'woocommerce_pay_order_before_submit' ); ?>
                <?php
                    if($get_gateway->title == "PayPal"){
                        echo apply_filters( 'woocommerce_pay_order_button_html', '<button type="submit" class="button alt" id="place_order" value="' . esc_attr( $get_gateway->order_button_text ) . '" data-value="' . esc_attr( $get_gateway->order_button_text ) . '">' . esc_html( $get_gateway->order_button_text ) . '</button>' ); 
                    }
                    else{
                        #echo apply_filters( 'woocommerce_pay_order_button_html', '<button type="submit" class="button alt" id="place_order" value="Pay now" data-value="pay now">pay now</button>' ); 
                        echo '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="Place order" data-value="Place order">Place order</button>';
                    }
                ?>
                <?php wp_nonce_field( 'woocommerce-pay', 'woocommerce-pay-nonce' ); ?>
                <?php do_action( 'woocommerce_pay_order_after_submit' ); ?>
                </form>
            <?php #endif; ?>
            <?php endforeach; ?>
    </div>
</div>
<?php
if ( ! is_ajax() ) {
    do_action( 'woocommerce_review_order_after_payment' );
}
?>

标签: phpwordpresswoocommercepaypalpayment-gateway

解决方案


推荐阅读