-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.php
118 lines (94 loc) · 4.13 KB
/
index.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
<?php
/*
Plugin Name: Barion Payment Gateway for WooCommerce
Plugin URI: http://github.com/szelpe/woocommerce-barion
Description: Adds the ability to WooCommerce to pay via Barion
Version: 3.8
Author: Aron Ocsvari <[email protected]>
Author URI: https://bitron.hu
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
WC requires at least: 3.0.0
WC tested up to: 9.3.3
Text Domain: pay-via-barion-for-woocommerce
Domain Path: /languages
*/
$plugin = new WooCommerce_Barion_Plugin();
class WooCommerce_Barion_Plugin {
/**
* @var WC_Gateway_Barion_Profile_Monitor
*/
private $profile_monitor;
private $wc_gateway_barion;
public function __construct() {
add_action('plugins_loaded', [$this, 'init'], 10);
}
function init() {
load_plugin_textdomain('pay-via-barion-for-woocommerce', false, plugin_basename(dirname(__FILE__)) . "/languages");
if (!class_exists('WC_Payment_Gateway'))
return;
require_once 'includes/class-wc-gateway-barion-profile-monitor.php';
$this->profile_monitor = new WC_Gateway_Barion_Profile_Monitor();
require_once 'class-wc-gateway-barion.php';
$this->wc_gateway_barion = new WC_Gateway_Barion($this->profile_monitor);
require_once 'includes/class-wc-gateway-barion-pixel.php';
$barion_pixel = new WC_Gateway_Barion_Pixel($this->wc_gateway_barion->get_barion_pixel_id());
add_filter('woocommerce_payment_gateways', [$this, 'woocommerce_add_gateway_barion_gateway']);
//Mark compatibility with checkout blocks
add_action( 'before_woocommerce_init', function() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
}
} );
//Load checkout block class
add_action( 'woocommerce_blocks_loaded', function() {
if( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
return;
}
require_once 'includes/class-wc-gateway-barion-block-checkout.php';
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$payment_method_registry->register( new WC_Gateway_Barion_Blocks );
} );
} );
//Adds notification to dashboard
add_action('admin_notices', array($this, 'custom_admin_ad_notice'));
add_action('wp_ajax_custom_admin_ad_dismiss', array($this, 'custom_admin_ad_dismiss'));
}
/**
* Shows a notification about Full Barion pixel
**/
function custom_admin_ad_notice() {
if (get_user_meta(get_current_user_id(), 'custom_admin_ad_dismissed', true)) {
return; // Ha igen, nem jelenítjük meg az értesítést
}
?>
<div class="notice notice-info is-dismissible custom-admin-ad-notice">
<p><?php _e('Reduce your Barion commission by using Full Pixel. Click here for more information: <a target ="_blank" href ="https://bitron.hu/barion-pixel-for-woocommerce">Full Barion Pixel for WooCommerce</a>', 'pay-via-barion-for-woocommerce'); ?></p>
</div>
<script>
jQuery(document).on('click', '.custom-admin-ad-notice .notice-dismiss', function() {
jQuery.post(ajaxurl, {
action: 'custom_admin_ad_dismiss'
});
});
</script>
<?php
}
/**
* Saves the dismiss option
**/
function custom_admin_ad_dismiss() {
update_user_meta(get_current_user_id(), 'custom_admin_ad_dismissed', true);
wp_die();
}
/**
* Add the Gateway to WooCommerce
**/
function woocommerce_add_gateway_barion_gateway($methods) {
$methods[] = $this->wc_gateway_barion;
return $methods;
}
}