1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace WC_POS;
13
14 class Gateways {
15
16 protected static $instance;
17
18 19 20
21 public function __construct() {
22 add_action( 'woocommerce_payment_gateways', array( $this, 'payment_gateways' ) );
23 add_action( 'woocommerce_pos_load_gateways', array( $this, 'load_gateways' ) );
24
25 static::$instance = $this;
26 }
27
28 29 30 31 32
33 public static function get_instance() {
34 $class = get_called_class();
35 if (null === static::$instance) {
36 static::$instance = new $class();
37 }
38 return static::$instance;
39 }
40
41 42 43 44 45
46 public function payment_gateways( array $gateways ) {
47 global $plugin_page;
48
49
50 if( is_admin() && $plugin_page == 'wc-settings' || !is_admin() && !is_pos() ){
51 return $gateways;
52 }
53
54 return array_merge($gateways, array(
55 'WC_POS\Gateways\Cash',
56 'WC_POS\Gateways\Card'
57 ));
58 }
59
60 61 62 63 64
65 public function load_gateways( $gateways ) {
66 foreach( $gateways as $gateway ){
67 $gateway->pos = in_array( $gateway->id, array( 'pos_cash', 'pos_card', 'paypal' ) );
68 }
69 return $gateways;
70 }
71
72 }