跳到主要内容

WooCommerce 支付网关插件基础

这段代码可以作为基础,用于创建您自己的简单的自定义支付网关,适用于 WooCommerce。 如果您没有将其用于自定义插件,则需要将此代码添加到子主题的 functions.php 文件中,或者通过允许添加自定义函数的插件,例如 Code snippets 插件。 请不要直接将自定义代码添加到父主题的 functions.php 文件中,因为在更新主题时,这些代码将被完全清除。

<?php
/*
Plugin Name: WooCommerce <enter name> 网关
Plugin URI: https://woothemes.com/woocommerce
Description: 为 WooCommerce 扩展一个 <enter name> 网关。
Version: 1.0
Author: WooThemes
Author URI: https://woothemes.com/
Copyright: © 2009-2011 WooThemes.
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_action('plugins_loaded', 'woocommerce_gateway_name_init', 0);
function woocommerce_gateway_name_init() {
if ( !class_exists( 'WC_Payment_Gateway' ) ) return;
/**
* 本地化
*/
load_plugin_textdomain('wc-gateway-name', false, dirname( plugin_basename( __FILE__ ) ) . '/languages');

/**
* 网关类
*/
class WC_Gateway_Name extends WC_Payment_Gateway {

// 您可以在这里自由发挥
}

/**
* 将网关添加到 WooCommerce
**/
function woocommerce_add_gateway_name_gateway($methods) {
$methods[] = 'WC_Gateway_Name';
return $methods;
}

add_filter('woocommerce_payment_gateways', 'woocommerce_add_gateway_name_gateway' );
}