我为新的支付网关创建了一个类。我刚刚复制了现有的付款类别&更改了类名,文件名以及安装代码。
但是我找不到在管理面板中安装新支付网关的方法。 请指教。
Wordpress Ver:3.5.1 类:
<?php
//if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* braintreedemo Payment Gateway
*
* Provides a braintreedemo Payment Gateway, mainly for testing purposes.
*
* @class WC_Gateway_braintreedemo
* @extends WC_Payment_Gateway
* @version 2.1.0
* @package WooCommerce/Classes/Payment
* @author WooThemes
*/
add_action('plugins_loaded', 'woocommerce_braintree_init', 0);
function woocommerce_braintree_init() {
if(!class_exists('WC_Payment_Gateway')) return;
class WC_Gateway_Braintree extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = 'braintree';
$this->icon = apply_filters('woocommerce_cheque_icon', '');
$this->has_fields = false;
$this->method_title = __( 'Craintreedemo', 'woocommerce' );
$this->method_description = __( 'Allows braintree payments. Why would you take braintree in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce' );
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions', $this->description );
// Actions
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_thankyou_braintree', array( $this, 'thankyou_page' ) );
// Customer Emails
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 2 );
}
/**
* Initialise Gateway Settings Form Fields
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable braintree Payment', 'woocommerce' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
'default' => __( 'braintree Payment', 'woocommerce' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'woocommerce' ),
'type' => 'textarea',
'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
'default' => __( 'Please send your braintree to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'woocommerce' ),
'desc_tip' => true,
),
'instructions' => array(
'title' => __( 'Instructions', 'woocommerce' ),
'type' => 'textarea',
'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
),
);
}
/**
* Output for the order received page.
*/
public function thankyou_page() {
if ( $this->instructions )
echo wpautop( wptexturize( $this->instructions ) );
}
/**
* Add content to the WC emails.
*
* @access public
* @param WC_Order $order
* @param bool $sent_to_admin
*/
public function email_instructions( $order, $sent_to_admin ) {
if ( $sent_to_admin || $order->status !== 'on-hold' || $order->payment_method !== 'braintree' )
return;
if ( $this->instructions )
echo wpautop( wptexturize( $this->instructions ) );
}
/**
* Process the payment and return the result
*
* @param int $order_id
* @return array
*/
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
// Mark as on-hold (we're awaiting the braintree)
$order->update_status( 'on-hold', __( 'Awaiting braintree payment', 'woocommerce' ) );
// Reduce stock levels
$order->reduce_order_stock();
// Remove cart
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
}
/**
* Add the Gateway to WooCommerce
**/
function woocommerce_add_braintree_gateway($methods) {
$methods[] = 'WC_Braintree';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_add_braintree_gateway' );
}
答案 0 :(得分:1)
下载此插件:https://wordpress.org/plugins/woocommerce-custom-payment-gateways/
查看代码,并在您看到'custom_payment_gateway'的任何地方输入您的网关名称。
以上代码应该指导您,我已经用它来创建自定义网关。
答案 1 :(得分:1)
步骤1。创建此文件夹: /可湿性粉剂内容/插件/ woocommerce支付网关-braintreedemo /
步骤2。将您的代码放入此文件woocommerce-payment-gateway-braintreedemo.php并将其放在步骤1中的该文件夹中。
步骤3。确保它位于php文件的顶部
<?php
/*
Plugin Name: WooCommerce braintreedemo Payment Gateway
Plugin URI: http://www.braintreedemo.com
Description: braintreedemo Payment gateway for woocommerce
Version: 1.0
Author: Your Name
Author URI: http://www.mywebsite.com
*/
步骤4.转到wordpress wp-admin插件页面并向下滚动到你的插件并按下激活。
步骤5.任何错误都将显示在页面顶部。如果语法错误确实很糟,请删除php文件以恢复您的网站。
答案 2 :(得分:0)
您需要以与安装WordPress插件相同的方式安装。
如果您的插件是正确的,那么当您转到WooCommerce设置时,您应该会看到启用网关的选项。