forked from TipiCode/Woocommerce-Recurrente
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recurrente-payment-gateway.php
133 lines (118 loc) · 3.59 KB
/
recurrente-payment-gateway.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Plugin Name: Recurrente Payment Gateway WooCommerce
* Plugin URI: https://github.com/TipiCode/woocommerce-gateway-recurrente
* Description: Recurrente Payment gateway extension for WooCommerce.
* Version: 1.0.5
* Requires PHP: 7.2
* Author: tipi(code)
* Author URI: https://codingtipi.com
* License: MIT
* WC requires at least: 5.8.0
* WC tested up to: 6.0.0
*
* @package RecurrenteGateway
*/
function Register_Recurrente_Order_status() {
$statuses = include 'inc/order-status-recurrente.php';
foreach ($statuses as $status) {
$label = $status['label'];
register_post_status(
$status['status'],
array(
'label' => $label,
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
/* translators: %s: count */
'label_count' => array(
$label . ' <span class="count">(%s)</span>', // NOSONAR.
$label . ' <span class="count">(%s)</span>' // NOSONAR.
),
)
);
}
}
add_action('init', 'Register_Recurrente_Order_status');
/**
* Function to register woocommerce order statuses
*
* @param array $order_statuses Order Statuses.
*/
function Recurrente_Order_status( $order_statuses) {
$statuses = include 'inc/order-status-recurrente.php';
$id = get_the_ID();
$action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
if ('shop_order' === get_post_type() && $id && isset($action) && 'edit' === $action) {
$order = wc_get_order($id);
if ($order) {
$current_status = $order->get_status();
foreach ($statuses as $status) {
if ('wc-' . $current_status === $status['status']) {
$order_statuses[$status['status']] = $status['label'];
}
}
}
} else {
foreach ($statuses as $status) {
$order_statuses[$status['status']] = $status['label'];
}
}
return $order_statuses;
}
add_filter('wc_order_statuses', 'Recurrente_Order_status');
global $wpdb;
/**
* Function to add action links
*
* @param $links Links.
*/
function Plugin_Action_Links_recurrente( $links) {
$plugin_links = array(
'<a href="admin.php?page=wc-settings&tab=checkout§ion=recurrente">' . esc_html__('Settings', 'woocommerce') . '</a>',
);
return array_merge($plugin_links, $links);
}
/**
* Filter to add action links
*/
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'Plugin_Action_Links_recurrente');
/**
* Print admin errors
*/
function Print_Errors_recurrente() {
settings_errors('recurrente_error');
}
/*
* The class itself, please note that it is inside plugins_loaded action hook
*/
add_action('plugins_loaded', 'Recurrente_Init_Gateway_class');
/**
* Initialise the gateway class
*/
function Recurrente_Init_Gateway_class() {
if (!class_exists('WC_Payment_Gateway')) {
return;
}
include_once 'inc/class-recurrente-gateway.php';
Recurrente_Gateway::get_instance()->init_hooks();
}
// define the woocommerce_gateway_icon callback
function filter_woocommerce_gateway_icon( $icon, $this_id ) {
if($this_id == "recurrente") {
$icon = "<img style='max-width: 100px;' src='".plugins_url('inc/assets/visaMaster.png', __FILE__)."' alt='recurrente icon' />";
}
return $icon;
}
add_filter( 'woocommerce_gateway_icon', 'filter_woocommerce_gateway_icon', 10, 2 );
/**
* Add to woocommorce gateway list
*
* @param array $gateways Gateways.
*/
function Recurrente_Add_Gateway_class( $gateways) {
$gateways[] = 'recurrente_gateway';
return $gateways;
}
add_filter('woocommerce_payment_gateways', 'Recurrente_Add_Gateway_class');