forked from hrsetyono/wc-ongkir-indonesia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-indo-shipping.php
104 lines (77 loc) · 2.27 KB
/
woocommerce-indo-shipping.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
<?php
/*
Plugin Name: WooCommerce Indonesia Shipping
Description: WooCommerce FREE Shipping plugin for JNE, TIKI, or POS. Requires purchase from RajaOngkir.
Plugin URI: -
Author: fork form The Syne Studio
Author URI: http://thesyne.com/
Version: 1.1.3b
*/
if(!defined('ABSPATH') ) { exit; } // exit if accessed directly
// check if WooCommerce active
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
if(!is_plugin_active('woocommerce/woocommerce.php') ) {
return false;
}
define('WCIS_DIR', plugins_url('', __FILE__) );
require_once 'admin/all.php';
require_once 'public/all.php';
/*
Inititate the Indo Shipping method
*/
new WCIS_Init();
class WCIS_Init {
private $settings;
private $enabled;
function __construct() {
$this->settings = get_option('woocommerce_wcis_settings');
$this->enabled = isset($this->settings['enabled']) ? $this->settings['enabled'] : 'no';
if($this->enabled === 'yes') {
$this->admin_init();
$this->waybill_init();
add_action('template_redirect', array($this, 'public_init') );
}
// run this code even if disabled
add_action('woocommerce_shipping_init', array($this, 'shipping_init') );
add_filter('woocommerce_shipping_methods', array($this, 'shipping_method') );
}
/* Class Airway Bills */
public function waybill_init(){
// Waybill
new WCIS_Waybill();
}
/*
Inititate the needed classes
*/
function admin_init() {
new WCIS_Ajax();
new WCIS_Checkout();
}
function public_init() {
if(is_checkout() ) {
new WCIS_Frontend();
}
// change default
// TODO: due to template_redirect action, Postcode might show up after refresh
add_filter('woocommerce_shipping_calculator_enable_city', '__return_true');
add_filter('woocommerce_shipping_calculator_enable_postcode', '__return_false');
}
/////
/*
Initiate WC Shipping
@filter woocommerce_shipping_init
*/
function shipping_init() {
require_once('admin/init-main.php');
require_once('admin/init-zones.php');
}
/*
Add our custom Shipping method
@filter woocommerce_shipping_methods
*/
function shipping_method($methods) {
$methods['wcis'] = 'WCIS_Method';
$methods['wcis_zone'] = 'WCIS_Zones_Method';
return $methods;
}
}