自定义WooCommerce付款网关未显示

时间:2018-04-26 19:18:02

标签: 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
     * @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设置页面的网关列表中。

enter image description here

我在这里错过了什么步骤?

0 个答案:

没有答案