This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgls-woocommerce.php
148 lines (125 loc) · 3.93 KB
/
gls-woocommerce.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
148
<?php
/**
* @formatter:off
* Plugin Name: GLS for WooCommerce
* Plugin URI: https://gls-group.eu/NL/nl/home
* Description: GLS offers shipping solutions nationally and internationally in Europe and worldwide. By using this plugin you can integrate GLS shipping methods in WooCommerce.
* Version: 1.5.2
* Author: TIG
* Author URI: https://tig.nl/
* Developer: TIG
* Developer URI: https://tig.nl/
* Text Domain: gls-woocommerce
*
* WC Requires at least: 3.8.1
* WC Tested up to: 6.0.0
*
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* @formatter:on
*/
if (!defined('ABSPATH')) {
exit;
}
if (!defined('GLS_PLUGIN_FILE')) {
define('GLS_PLUGIN_FILE', __FILE__);
}
/**
* Add Shipping Options before Order Review in WooCommerce Checkout if any items
* in cart require shipping.
*/
function tig_gls_delivery_options()
{
if (!GLS::is_gls_enabled_in_any_zone()) {
return;
}
include_once dirname(__FILE__) . '/templates/checkout/delivery-options.php';
}
add_action('woocommerce_checkout_before_order_review_heading', 'tig_gls_delivery_options');
/**
*
*/
function tig_gls_settings_tab($settings)
{
$settings[] = include 'includes/admin/settings/class-gls-settings-delivery-options.php';
return $settings;
}
add_filter('woocommerce_get_settings_pages', 'tig_gls_settings_tab');
/**
* Adds the GLS shipping method.
*/
function tig_gls_shipping_method()
{
if (!class_exists('GLS_Shipping_Method')) {
class GLS_Shipping_Method extends WC_Shipping_Flat_Rate
{
const GLS_SHIPPING_METHOD_ID = 'tig_gls';
/**
* GLS_Shipping_Method constructor.
*
* @param int $instance_id
*/
public function __construct(
$instance_id = 0
) {
$this->id = self::GLS_SHIPPING_METHOD_ID;
$this->instance_id = absint($instance_id);
$this->plugin_id = self::GLS_SHIPPING_METHOD_ID;
$this->method_title = __('GLS', 'gls-woocommerce');
$this->method_description = __('Connect WooCommerce to GLS to provide GLS delivery options in checkout.', 'gls-woocommerce');
$this->supports = array(
'shipping-zones',
'instance-settings',
'instance-settings-modal'
);
$this->init();
}
public function init()
{
$this->init_settings();
add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));
parent::init();
}
public function init_form_fields()
{
$this->form_fields = array(
);
}
}
}
}
add_action('woocommerce_shipping_init', 'tig_gls_shipping_method');
/**
* @param $methods
*
* @return array
*/
function tig_gls_add_shipping_method($methods)
{
$methods[GLS_Shipping_Method::GLS_SHIPPING_METHOD_ID] = 'GLS_Shipping_Method';
return $methods;
}
add_filter('woocommerce_shipping_methods', 'tig_gls_add_shipping_method');
/**
* We're wrapping the initialization in this function, which will be triggered
* when all plugins (and WooCommerce) are loaded. This way we are sure that this
* plugin is loaded after WooCommerce.
*/
function tig_gls_init_after_woocommerce()
{
if (!class_exists('GLS', false)) {
include_once dirname(__FILE__) . '/includes/class-gls.php';
}
/**
* Return the Main Instance of GLS
*
* @return GLS
*/
function GLS()
{ // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return GLS::instance();
}
// Global for backwards compatibility.
$GLOBALS['tig_gls'] = GLS();
}
add_action('woocommerce_loaded', 'tig_gls_init_after_woocommerce');