-
Notifications
You must be signed in to change notification settings - Fork 13
/
woocommerce-geolocation-based-products.php
147 lines (123 loc) · 4.17 KB
/
woocommerce-geolocation-based-products.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Plugin Name: WooCommerce Geolocation Based Products
* Plugin URI: https://wordpress.org/plugins/woocommerce-geolocation-based-products/
* Description: A WooCommerce plugin/extension that adds ability for your store to hide products based on visitors geolocation.
* Version: 1.5.4
* Author: Roy Ho
* Author URI: https://royho.me
* Text Domain: woocommerce-geolocation-based-products
* Domain Path: /languages
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Geolocation_Based_Products' ) ) :
define( 'WC_GEOLOCATION_BASED_PRODUCTS_VERSION', '1.5.4' );
register_activation_hook( __FILE__, 'wc_glbp_activation' );
/**
* Activation tasks
*
* @since 1.5.0
* @version 1.5.3
* @return bool
*/
function wc_glbp_activation() {
add_option( 'wc_glbp_version', WC_GEOLOCATION_BASED_PRODUCTS_VERSION, '', 'no' );
return true;
}
/**
* main class.
*
* @package WC_Geolocation_Based_Products
*/
class WC_Geolocation_Based_Products {
private static $_this;
/**
* init
*
* @since 1.0.0
* @version 1.5.4
* @return bool
*/
public function __construct() {
self::$_this = $this;
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// Required functions
require_once( 'woo-includes/woo-functions.php' );
if ( is_woocommerce_active() ) {
if ( is_admin() ) {
require_once( dirname( __FILE__ ) . '/includes/class-wc-geolocation-based-products-admin.php' );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
} else {
require_once( dirname( __FILE__ ) . '/vendor/autoload.php' );
require_once( dirname( __FILE__ ) . '/includes/class-wc-geolocation-based-products-geolocate.php' );
require_once( dirname( __FILE__ ) . '/includes/class-wc-geolocation-based-products-frontend.php' );
}
} else {
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
}
return true;
}
/**
* public access to instance object
*
* @since 1.1.1
* @version 1.5.3
* @return bool
*/
public static function get_instance() {
return self::$_this;
}
/**
* load the plugin text domain for translation.
*
* @since 1.0.0
* @return bool
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'wc_geolocation_based_products_plugin_locale', get_locale(), 'woocommerce-geolocation-based-products' );
load_textdomain( 'woocommerce-geolocation-based-products', trailingslashit( WP_LANG_DIR ) . 'woocommerce-geolocation-based-products/woocommerce-geolocation-based-products' . '-' . $locale . '.mo' );
load_plugin_textdomain( 'woocommerce-geolocation-based-products', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
return true;
}
/**
* WooCommerce fallback notice.
*
* @return string
*/
public function woocommerce_missing_notice() {
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Geolocation Based Products Plugin requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-geolocation-based-products' ), '<a href="https://wordpress.org/support/plugin/woocommerce" target="_blank">WooCommerce</a>' ) . '</p></div>';
}
/**
* Show action links on the plugin screen
*
* @param mixed $links
* @return array
*/
public function action_links( $links ) {
return array_merge( $links, array(
'<a href="' . admin_url( 'edit.php?post_type=product&page=geolocation_products' ) . '">' . __( 'Settings', 'woocommerce-geolocation-based-products' ) . '</a>',
) );
}
}
if ( ! function_exists( 'woocommerce_geolocation_based_products_init' ) ) :
add_action( 'plugins_loaded', 'woocommerce_geolocation_based_products_init', 0 );
endif;
/**
* init function
*
* @package WC_Geolocation_Based_Products
* @since 1.0.0
* @return bool
*/
function woocommerce_geolocation_based_products_init() {
new WC_Geolocation_Based_Products();
return true;
}
endif;