forked from MIKEINTOSHSYSTEMS/chapa-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woo-chapa.php
80 lines (65 loc) · 2.26 KB
/
woo-chapa.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
Plugin Name: Chapa Payment Gateway Plugin for WooCommerce
Plugin URI: https://chapa.co/
Description: Chapa Payment Gateway Plugin for WooCommerce
Version: 1.0.1
Author: Chapa
License: GPL-2.0+
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
WC requires at least: 3.0.0
WC tested up to: 6.3.1
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'WAF_WC_CHAPA_MAIN_FILE', __FILE__ );
define( 'WAF_WC_CHAPA_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
define( 'WAF_WC_CHAPA_VERSION', '1.0.1' );
/**
* Initialize Chapa WooCommerce payment gateway.
*/
function waf_wc_chapa_init() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
return;
}
require_once dirname( __FILE__ ) . '/includes/class-waf-wc-chapa-gateway.php';
add_filter( 'woocommerce_payment_gateways', 'waf_wc_add_chapa_gateway' );
add_filter( 'woocommerce_available_payment_gateways', 'conditionally_hide_waf_chapa_payment_gateways' );
}
add_action( 'plugins_loaded', 'waf_wc_chapa_init' );
/**
* Add Settings link to the plugin entry in the plugins menu
**/
function waf_wc_chapa_plugin_action_links( $links ) {
$settings_link = array(
'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=waf_chapa' ) . '" title="View Settings">Settings</a>'
);
return array_merge( $settings_link, $links );
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'waf_wc_chapa_plugin_action_links' );
/**
* Add Chapa Gateway to WC
**/
function waf_wc_add_chapa_gateway( $methods ) {
$methods[] = 'Waf_WC_chapa_Gateway';
return $methods;
}
/**
* @param $available_gateways
* @return mixed
* Hide Chapa Condition payment method if the currency is not one of the following: ETB, USD, GBP, EUR
*/
function conditionally_hide_waf_chapa_payment_gateways( $available_gateways ) {
// Not in backend (admin)
if( is_admin() ){
return $available_gateways;
}
$chapa_api = new Waf_WC_chapa_Gateway();
$available_currencies = $chapa_api->get_supported_currencies();
$currency = get_woocommerce_currency();
if(array_search($currency, $available_currencies) === false){
unset($available_gateways['waf_chapa']);
}
return $available_gateways;
}