woocommerce: so installieren Sie den Custom Payment Gateway
Habe ich eine Klasse angelegt, die für neue payment-gateway. Ich habe gerade dupliziert die bestehende Zahlungs-Klasse & verändert die Klasse, name, Datei name und umfasste auch die Installation von code.
Aber ich konnte nicht finden die Art und Weise zu installieren, eine neue payment-gateway im admin-panel.
Bitte um Rat.
WordPress-Version: 3.5.1
Klasse:
<?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' );
}
InformationsquelleAutor user2870431 | 2014-04-03
Du musst angemeldet sein, um einen Kommentar abzugeben.
download dieses plugin: https://wordpress.org/plugins/woocommerce-custom-payment-gateways/
Blick auf den code, und überall sehen Sie 'custom_payment_gateway" setzen Sie den Namen des Gateways ein.
Der obige code sollte Euch führen, ich habe es verwendet, um eine benutzerdefinierte gateway.
InformationsquelleAutor Anthony Essel
step1. erstellen Sie in diesem Ordner:
/wp-content/plugins/woocommerce-payment-gateway-braintreedemo/
step2. fügen Sie Ihren code in diese Datei ein woocommerce-payment-gateway-braintreedemo.php und legen Sie Sie in den Ordner aus Schritt 1.
Schritt 3. dies sicherzustellen, ist an der Spitze der php-Datei
Schritt 4. springen die wordpress wp-admin-Plugin-Seite und scrollen Sie nach unten, um das plugin und drücken Sie aktivieren.
Schritt 5. alle Fehler werden angezeigt, die am oberen Rand der Seite. löschen Sie die php-Datei zum wiederherstellen Ihrer Seite, wenn es wirklich schlechte syntax-Fehler.
InformationsquelleAutor hamish
Müssen Sie installieren die gleiche Weise installieren ein WordPress-plugin.
Wenn das plugin korrekt ist, dann wenn Sie gehen, um WooCommerce-Einstellungen sollten Sie die option aktivieren, Ihre gateway.
InformationsquelleAutor Federico Giust