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

WooCommerce结账页面自定义支付方式选项不显示求助

WooCommerce自定义支付网关无法在结账页面显示排查求助

我正在尝试将自定义支付方式集成到WooCommerce,已成功在后台添加启用/禁用该支付方式的选项,但它无法在结账页面显示。试过多种解决方案都未解决,附上相关截图及插件代码,请求协助排查问题。

相关截图

  • 后台配置页面截图:后台配置页面截图
  • 前端结账页面截图:前端结账页面截图

自定义支付网关插件代码

<?php
/*
Plugin Name: SecureNet Payment Gateway
Version: 1.0
Description: Add SecureNet Payment as a payment option in WooCommerce.
Author: Your Name
*/

// Define the custom payment gateway class
function custom_payment_gateway_init() {
    class Custom_Payment_Gateway extends WC_Payment_Gateway {
        public function __construct() {
            $this->id = 'custom_payment_gateway'; // Unique ID for your payment gateway
            $this->method_title = 'Custom Payment Gateway';
            $this->method_description = 'Add a custom description here.';
            $this->has_fields = true;
            $this->init_form_fields();
            $this->init_settings();
            $this->title = $this->get_option('title');
            $this->description = $this->get_option('description');
            // Add more settings here
            // ...
            add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
        }

        public function init_form_fields() {
            $this->form_fields = array(
                'title' => array(
                    'title' => __('Title', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('This controls the title displayed during checkout.', 'woocommerce'),
                    'default' => __('Custom Payment Gateway', 'woocommerce'),
                    'desc_tip' => true,
                ),
                'description' => array(
                    'title' => __('Description', 'woocommerce'),
                    'type' => 'textarea',
                    'description' => __('This controls the description displayed during checkout.', 'woocommerce'),
                    'default' => __('Pay using Custom Payment Gateway', 'woocommerce'),
                    'desc_tip' => true,
                ),
                // Add more fields here
                // ...
            );
        }

        public function process_payment($order_id) {
            // Handle payment processing logic here
            // Connect to your payment gateway API, redirect to payment page, and confirm payment
            // Implement error handling and status updates
            // ...

            return array(
                'result' => 'success', // or 'failure' for unsuccessful payments
                'redirect' => $redirect_url, // URL to redirect the customer for payment
            );
        }

        public function payment_fields() {
            // Display payment fields such as credit card info or other required info
            // ...

            // Example: You can use WooCommerce form fields to capture payment information
            echo '<div id="custom-payment-gateway-form">';
            // Display fields here
            echo '</div>';
        }

        public function validate_fields() {
            // Validate payment fields submitted by the customer
            // Implement validation logic
            // ...

            // Example validation:
            if (empty($_POST['custom_field'])) {
                wc_add_notice(__('Custom field is required.', 'woocommerce'), 'error');
            }
        }
    }
}

// Hook the custom_payment_gateway_init function to plugins_loaded action
add_action('plugins_loaded', 'custom_payment_gateway_init');

// Add custom payment gateway to available payment gateways in checkout
add_filter('woocommerce_payment_gateways', 'add_custom_payment_gateway');
function add_custom_payment_gateway($gateways) {
    $gateways[] = 'Custom_Payment_Gateway';
    return $gateways;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 04:53:11