forked from wp-plugins/fedex-woocommerce-shipping-method
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fedex-woocommerce-shipping.php
77 lines (64 loc) · 2.62 KB
/
fedex-woocommerce-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
<?php
/*
Plugin Name: FedEx Shipping for WooCommerce Shipping Zones
Description: Fedex Real Time Rates with WooCommerce 2.6+ Zone Support
Version: 1.0
Author: Cody Sand
Author URI: http://www.codysand.com
*/
/**
* Check if WooCommerce is active
*/
if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
if (!function_exists('wf_plugin_override')){
add_action( 'plugins_loaded', 'wf_plugin_override' );
function wf_plugin_override() {
if (!function_exists('WC')){
function WC(){
return $GLOBALS['woocommerce'];
}
}
}
}
if (!function_exists('wf_get_shipping_countries')){
function wf_get_shipping_countries(){
$woocommerce = WC();
$shipping_countries = method_exists($woocommerce->countries, 'get_shipping_countries')
? $woocommerce->countries->get_shipping_countries()
: $woocommerce->countries->countries;
return $shipping_countries;
}
}
if(!class_exists('wf_fedex_woocommerce_shipping_setup')){
class wf_fedex_woocommerce_shipping_setup {
public function __construct() {
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
add_action( 'woocommerce_shipping_init', array( $this, 'wf_fedex_woocommerce_shipping_init' ) );
add_filter( 'woocommerce_shipping_methods', array( $this, 'wf_fedex_woocommerce_shipping_methods' ) );
add_filter( 'admin_enqueue_scripts', array( $this, 'wf_fedex_scripts' ) );
$fedex_settings = get_option( 'woocommerce_wf_fedex_woocommerce_shipping_method_settings', array() );
if ( isset( $fedex_settings['freight_enabled'] ) && 'yes' === $fedex_settings['freight_enabled'] ) {
// Make the city field show in the calculator (for freight)
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_true' );
}
}
public function wf_fedex_scripts() {
wp_enqueue_script( 'jquery-ui-sortable' );
}
public function plugin_action_links( $links ) {
$plugin_links = array(
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=wf_fedex_woocommerce_shipping_method' ) . '">' . __( 'Settings', 'wf_fedex_woocommerce_shipping_method' ) . '</a>',
);
return array_merge( $plugin_links, $links );
}
public function wf_fedex_woocommerce_shipping_init() {
include_once( 'includes/class-wf-fedex-woocommerce-shipping.php' );
}
public function wf_fedex_woocommerce_shipping_methods( $methods ) {
$methods['wf_fedex_woocommerce_shipping_method'] = 'wf_fedex_woocommerce_shipping_method';
return $methods;
}
}
new wf_fedex_woocommerce_shipping_setup();
}
}