WordPress 插件 WooCommerce,自定义支付网关设置未保存 [英] WordPress Plugin WooCommerce, Custom Payment Gateway Settings Not Saving

查看:34
本文介绍了WordPress 插件 WooCommerce,自定义支付网关设置未保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 WordPress 插件 WooCommerce 开发自定义支付网关.我似乎无法保存支付网关的设置.当我在字段中输入信息然后单击保存时,页面刷新,所有字段都为空白.我做错了什么?

I'm working on a custom payment gateway for the WordPress plugin WooCommerce. I cannot seem to save the settings for the payment gateway. When I enter information into the fields and then click save, the page refreshes with all of the fields blank. What am I doing wrong?

这是我的代码.

<?php
/**
 * Plugin Name: Bitcoin WooCommerce Integration Made Easy
 * Description: A Bitcoin processing plugin that integrates into WooCommerce made specifically for Bitcoin Publish.
 * Version: 0.01
 * Author: Cammy_the_block
 */

add_action( 'plugins_loaded', 'init_your_gateway_class' );

function init_your_gateway_class() {
    class WC_Gateway_Your_Gateway extends WC_Payment_Gateway {
        function __construct() {
            $this->id = "Bitcoin WooCommerce Integration Gateway";
            $this->method_title = "Bitcoin with BWCIME";
            $this->method_description = "More later";

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

            if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
                    add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
            } 
            else {
                    add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
            }
        }
        function init_form_fields(){
            $this->form_fields = array(
                    'enabled' => array(
                            'title' => __( 'Enable/Disable', 'woocommerce' ),
                            'type' => 'checkbox',
                            'label' => __( 'Enable Cheque Payment', 'woocommerce' ),
                            'default' => 'yes'
                    ),
                    'title' => array(
                            'title' => __( 'Title', 'woocommerce' ),
                            'type' => 'text',
                            'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
                            'default' => __( 'Cheque Payment', 'woocommerce' ),
                            'desc_tip' => true,
                    ),
                    'description' => array(
                            'title' => __( 'Customer Message', 'woocommerce' ),
                            'type' => 'textarea',
                            'default' => ''
                    )
            );
        }
    }
    function process_payment( $order_id ) {
        global $woocommerce;
        $order = new WC_Order( $order_id );
        $productArray = array();
        $x = 0;
        foreach( $order->get_items() as $item_id => $item ) {
            $productArray[x] = $order->get_product_from_item( $item );
            $x++;
        }

        // Mark as on-hold (we're awaiting the cheque)
        $order->update_status('on-hold', 
        __( 'Awaiting cheque payment. there are ' + $productArray.length + 'items', 'woocommerce' )
        );


        // Remove cart
        $woocommerce->cart->empty_cart();

        // Return thankyou redirect
        return array(
            'result' => 'success',
            'redirect' => $this->get_return_url( $order )
        );
    }
}
function add_your_gateway_class ($methods ) {
    $methods[] = 'WC_Gateway_Your_Gateway'; 
    return $methods;
}

add_filter( 'woocommerce_payment_gateways', 'add_your_gateway_class' );
 ?>

添加过滤器代码运行 add_your_gateway_class,这反过来又使其运行 WC_Gateway_Your_Gateway.

The add filter code runs add_your_gateway_class, which in turn causes it to run WC_Gateway_Your_Gateway.

推荐答案

我不完全确定我是如何修复它的,但我相信它与添加函数 admin_options() 有关.

I'm not completely sure how I fixed it, but I believe it had to do with adding the function admin_options().

 public function admin_options() {
 ?>
            <h3><?php _e('Bitcoin Payment', 'woothemes'); ?></h3>
            <p><?php _e('Message!.', 'woothemes'); ?></p>
            <table class="form-table">
            <?php
                // Generate the HTML For the settings form.
                $this->generate_settings_html();
            ?>
            </table>
            <?php
} 

我不确定是什么原因造成的,但您必须通过与数据库交互来清除插件的设置.最简单的方法是更改​​插件的 ID.我实际上不确定这些设置在数据库中的存储位置.

这篇关于WordPress 插件 WooCommerce,自定义支付网关设置未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆