Skip to content

Instantly share code, notes, and snippets.

@kilbot
Last active February 1, 2024 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kilbot/bee9db75cd3671b837f4b48e1e1187c0 to your computer and use it in GitHub Desktop.
Save kilbot/bee9db75cd3671b837f4b48e1e1187c0 to your computer and use it in GitHub Desktop.
Simple plugin to add multiple gateways for WooCommerce POS Pro
<?php
/**
* Plugin Name: WooCommerce POS Gateways
* Plugin URI: https://wordpress.org/plugins/woocommerce-pos/
* Description: Extends WooCommerce with multiple POS gateways.
* Version: 1.0.0
* Author: kilbot
* Author URI: http://wcpos.com
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*/
namespace WCPOS;
use WC_Payment_Gateway;
/**
* Gateway class.
*
* Requires WooCommerce to be loaded first.
*/
add_action(
'woocommerce_loaded',
function () {
/**
* Gateway 1
*/
class POS_Gateway_1 extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = 'pos_gateway_1';
$this->title = 'POS Gateway 1';
$this->description = '';
$this->has_fields = false;
$this->enabled = 'no';
}
/**
* Process the payment and return the result.
*/
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
$order->payment_complete();
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order ),
);
}
}
/**
* Gateway 2
*/
class POS_Gateway_2 extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = 'pos_gateway_2';
$this->title = 'POS Gateway 2';
$this->description = '';
$this->has_fields = false;
$this->enabled = 'no';
}
/**
* Process the payment and return the result.
*/
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
$order->payment_complete();
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order ),
);
}
}
/**
* Gateway 3
*/
class POS_Gateway_3 extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = 'pos_gateway_3';
$this->title = 'POS Gateway 3';
$this->description = '';
$this->has_fields = false;
$this->enabled = 'no';
}
/**
* Process the payment and return the result.
*/
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
$order->payment_complete();
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order ),
);
}
}
/**
* Add the Gateways to WooCommerce.
*/
add_filter(
'woocommerce_payment_gateways',
function ( $gateways ) {
$gateways[] = 'WCPOS\POS_Gateway_1';
$gateways[] = 'WCPOS\POS_Gateway_2';
$gateways[] = 'WCPOS\POS_Gateway_3';
return $gateways;
}
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment