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

WooCommerce自定义支付网关插件未在结账页显示求助

自定义WooCommerce支付网关插件不显示在结账页面

我为WooCommerce开发了一款自定义支付网关插件,插件激活无任何报错,调试日志显示网关类已完成注册与初始化,但该支付方式并未在WooCommerce结账页面显示,页面仅提示“无可用支付方式”。

插件完整代码

<?php
/**
 * Plugin name: Noob Payment for Woocommerce
 * Plugin URI: http://www.insafinhaam.com/custom-woocommerce-payment-gateway-plugin
 * Author: Insaf Inhaam
 * Author URI: https://insafinhaam.com/
 * Description: This Plugin allows for local content payment system
 * Version: 1.0.0
 * License: 0.1.0
 * Text Domain: noob-pay-woo
 */

if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
    return;

add_action('plugins_loaded', 'noob_payment_init', 11);

function noob_payment_init()
{
    if (class_exists('WC_Payment_Gateway')) {
        class WC_Noob_pay_Gateway extends WC_Payment_Gateway
        {
            public function __construct()
            {
                $this->id = 'noob_payment';
                $this->icon = apply_filters('woocommerce_noob_icon', plugins_url('/assets/icon.png', __FILE__));
                $this->has_fields = false;
                $this->method_title = __('Noob Payment', 'noob-pay-woo');
                $this->method_description = __('Noob local content payment systems.', 'noob-pay-woo');

                $this->title = $this->get_option('title');
                $this->description = $this->get_option('description');
                $this->instructions = $this->get_option('instructions', $this->description);

                $this->init_form_fields();
                $this->init_settings();

                add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
                // add_action( 'woocommerce_thank_you_' . $this->id, array( $this, 'thank_you_page' ) );
            }

            public function init_form_fields()
            {
                $this->form_fields = apply_filters('woo_noob_pay_fields', array(
                    'enabled' => array(
                        'title' => __('Enable/Disable', 'noob-pay-woo'),
                        'type' => 'checkbox',
                        'label' => __('Enable or Disable Noob Payments', 'noob-pay-woo'),
                        'default' => 'no'
                    ),
                    'title' => array(
                        'title' => __('Noob Payments Gateway', 'noob-pay-woo'),
                        'type' => 'text',
                        'default' => __('Noob Payments Gateway', 'noob-pay-woo'),
                        'desc_tip' => true,
                        'description' => __('Add a new title for the Noob Payments Gateway that customers will see when they are in the checkout page.', 'noob-pay-woo')
                    ),
                    'description' => array(
                        'title' => __('Noob Payments Gateway Description', 'noob-pay-woo'),
                        'type' => 'textarea',
                        'default' => __('Please remit your payment to the shop to allow for the delivery to be made', 'noob-pay-woo'),
                        'desc_tip' => true,
                        'description' => __('Add a new title for the Noob Payments Gateway that customers will see when they are in the checkout page.', 'noob-pay-woo')
                    ),
                    'instructions' => array(
                        'title' => __('Instructions', 'noob-pay-woo'),
                        'type' => 'textarea',
                        'default' => __('Default instructions', 'noob-pay-woo'),
                        'desc_tip' => true,
                        'description' => __('Instructions that will be added to the thank you page and order email', 'noob-pay-woo')
                    ),
                    // 'enable_for_virtual' => array(
                    //     'title'   => __( 'Accept for virtual orders', 'woocommerce' ),
                    //     'label'   => __( 'Accept COD if the order is virtual', 'woocommerce' ),
                    //     'type'    => 'checkbox',
                    //     'default' => 'yes',
                    // ),
                )
                );
            }

            public function process_payments($order_id)
            {

                $order = wc_get_order($order_id);

                $order->update_status('on-hold', __('Awaiting Noob Payment', 'noob-pay-woo'));

                // if ( $order->get_total() > 0 ) {
                // Mark as on-hold (we're awaiting the cheque).
                // } else {
                // $order->payment_complete();
                // }

                // $this->clear_payment_with_api();

                $order->reduce_order_stock();

                WC()->cart->empty_cart();

                return array(
                    'result' => 'success',
                    'redirect' => $this->get_return_url($order),
                );
            }

            // public function clear_payment_with_api() {

            // }

            public function thank_you_page()
            {
                if ($this->instructions) {
                    echo wpautop($this->instructions);
                }
            }
        }
    }
}

add_filter('woocommerce_payment_gateways', 'add_to_woo_noob_payment_gateway');

function add_to_woo_noob_payment_gateway($gateways)
{
    $gateways[] = 'WC_Noob_pay_Gateway';
    return $gateways;
}

已尝试操作

  • 确认WooCommerce已激活;
  • 验证插件激活无报错;
  • 查看WordPress调试日志,显示WC_Simple_Noob_Pay_Gateway类已注册并初始化。

结果对比

预期结果:“Noob Payment”支付方式应在WooCommerce结账页显示为可选支付选项。
实际结果:结账页显示提示信息:“无可用支付方式。这可能是我们的错误。如果您需要帮助下单,请联系我们。”

结账页无可用支付方式提示
支付网关设置页面

恳请帮助解决此问题,谢谢!


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 23:30:13