Woocommerce 自定义电子商务支付网关未显示

Woocommerce 自定义电子商务支付网关未显示,woocommerce,Woocommerce,我创建了一个自定义WooCommerce 3.0支付网关来处理信用卡: add_action('plugins_loaded', 'wc_custom_gateway_init'); function wc_custom_gateway_init() { /** * custom Payment Gateway * * @class WC_Gateway_custom * @extends WC_Payment_Gateway * @v

我创建了一个自定义WooCommerce 3.0支付网关来处理信用卡:

add_action('plugins_loaded', 'wc_custom_gateway_init');

function wc_custom_gateway_init()
{
    /**
     * custom Payment Gateway
     *
     * @class WC_Gateway_custom
     * @extends WC_Payment_Gateway
     * @version 1.0.0
     * @package WooCommerce/Classes/Payment
     */
    class WC_Gateway_custom extends WC_Payment_Gateway
    {
        public function __construct()
        {
            $this->id = 'custom';
            $this->icon = null;
            $this->has_fields = true;
            $this->method_title = 'custom';
            $this->method_description = 'custom payment gateway';

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

        /**
         * Initialize Gateway Settings Form Fields
         */
        public function init_form_fields()
        {
            $this->form_fields = [
                'enabled'      => [
                    'title'   => __('Enable/Disable', 'wc-gateway-custom'),
                    'type'    => 'checkbox',
                    'label'   => __('Enable custom Payment', 'wc-gateway-custom'),
                    'default' => 'yes'
                ],
                // This controls the title for the payment method the customer sees during checkout.
                'title'        => [
                    'title'       => __('Title', 'wc-gateway-custom'),
                    'type'        => 'text',
                    'description' => __('Credit Card', 'wc-gateway-custom'),
                    'default'     => __('Credit Card', 'wc-gateway-custom'),
                    'desc_tip'    => true,
                ],
                // Payment method description that the customer will see on your checkout.
                'description'  => [
                    'title'       => __('Description', 'wc-gateway-custom'),
                    'type'        => 'textarea',
                    'description' => __('Credit Card', 'wc-gateway-custom'),
                    'default'     => __('Credit Card', 'wc-gateway-custom'),
                    'desc_tip'    => true,
                ],
                // Instructions that will be added to the thank you page and emails.
                'instructions' => [
                    'title'       => __('Instructions', 'wc-gateway-custom'),
                    'type'        => 'textarea',
                    'description' => __('', 'wc-gateway-custom'),
                    'default'     => '',
                    'desc_tip'    => true,
                ],
            ];
        }

        /**
         * @param int $order_id
         *
         * @return array|null
         */
        public function process_payment($order_id)
        {
            $order = wc_get_order($order_id);

            // ... API call and various validation logic...

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

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

    /**
     * Add the gateway to the WC list.
     *
     * @param array $gateways
     *
     * @return array
     */
    function wc_custom_add_to_gateways($gateways)
    {
        $gateways[] = 'WC_Gateway_custom';

        return $gateways;
    }

    add_filter('woocommerce_payment_gateways', 'wc_custom_add_to_gateways');
}
但是,自定义网关从未显示在WC设置页面上的网关列表中


我在这里遗漏了什么步骤?

你应该在一个插件文件中创建它(tested and works)@LoicTheAztec,这就是我遵循的示例。我把实际的插件文件放在哪里?我在
wp-content/plugins/custom-payment-gateway/custom-payment-gateway.php下添加了我的插件文件。我尝试直接创建它,但得到的
包无法安装。找不到有效的插件。
当我尝试将其上载到插件页面进行安装时,您的代码并不完整,因为您需要像教程中那样指定程序包名称…==>@package