forked from Homerunner-com/woocommerce-smartcheckout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coolrunner_smartcheckout.php
111 lines (97 loc) · 4.22 KB
/
coolrunner_smartcheckout.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
<?php
/**
* Plugin Name: HomeRunner - SmartCheckout
* Plugin URI: https://homerunner.com/
* Description: With HomeRunner SmartCheckout you will be able to setup rules, conditions and much more for your shipping so you are able to provide the best possible solution for your customer.
* Version: 0.5.0
* Author: HomeRunner
* Author URI: https://homerunner.com
* Developer: Kevin Steen Hansen / CoolRunHomeRunnerner
* Developer URI: https://homerunner.com
* Text Domain: csc_textdomain
* Domain Path: /languages
*
* WC requires at least: 3.4.2
* WC tested up to: 3.4.2
*
* Copyright: © 2023 - HomeRunner.dk
* License: MIT
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
define( 'CSC_WOOCOMMERCE_VERSION', '1.1' );
define( 'CSC_PLUGIN_FILE', __FILE__ );
define( 'CSC_PLUGIN_URL', plugins_url( '', __FILE__ ) );
define( 'CSC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'CSC_PLUGIN_VERSION', '0.5.0' );
// Check if WooCommerce is installed - This is required for this plugin
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
add_action( 'admin_notices', function () {
?>
<div class="notice notice-warning">
<p><?php _e( 'HomeRunner SmartCheckout requires WooCommerce to be installed and active.', 'csc_textdomain' ); ?></p>
<p><?php _e( 'You download WooCommerce here:', 'csc_textdomain' ); ?><?php echo sprintf( '<a href="%s/wp-admin/plugin-install.php?s=WooCommerce&tab=search&type=term">Download</a>', get_site_url() ) ?></p>
</div>
<?php
} );
return;
} else {
// Add translations to plugin
add_action( 'plugins_loaded', 'csc_load_textdomain' );
function csc_load_textdomain() {
load_plugin_textdomain( 'csc_textdomain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
// Add links on plugins overview page
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'crship_action_links' );
function crship_action_links( $links ) {
$links[] = '<a href="' . admin_url( 'admin.php?page=csc-options' ) . '">' . __( 'Settings', 'csc_textdomain' ) . '</a>';
$links[] = '<a href="https://homerunner.com/" target="_blank">' . __( 'Read more about HomeRunner', 'csc_textdomain' ) . '</a>';
return $links;
}
// Add CSS to checkout
add_action( 'wp_enqueue_scripts', function () {
if ( is_checkout() ) {
wp_enqueue_style( 'csc', plugins_url( '/assets/css/csc.css', __FILE__ ), array(), CSC_WOOCOMMERCE_VERSION );
wp_enqueue_script( 'csc', plugins_url( '/assets/js/csc.js', __FILE__ ), array( 'jquery' ), CSC_WOOCOMMERCE_VERSION, true );
wp_localize_script( 'csc', 'csc', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'lang' => array(
'droppoint_searching' => __( 'Searching for droppoints!', 'csc_textdomain' )
)
) );
}
} );
// Add CSS to admin
add_action( 'admin_enqueue_scripts', function () {
wp_enqueue_style( 'csc', plugins_url( '/assets/css/admin-csc.css', __FILE__ ), array(), CSC_WOOCOMMERCE_VERSION );
wp_enqueue_script( 'csc', plugins_url( '/assets/js/admin.js', __FILE__ ), array( 'jquery' ), CSC_WOOCOMMERCE_VERSION, true );
});
// Add JS to checkout
add_action( 'wp_enqueue_scripts', function () {
if ( is_checkout() ) {
wp_enqueue_script( 'csc', plugins_url( '/assets/js/csc.js', __FILE__ ), array( 'jquery' ), CSC_WOOCOMMERCE_VERSION, true );
wp_localize_script( 'csc', 'csc', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'lang' => array(
'droppoint_searching' => __( 'Searching for droppoints!', 'csc_textdomain' )
)
) );
}
} );
// Handle rates
add_action('woocommerce_shipping_init', function () {
if(class_exists('SmartCheckoutRates')) {
return;
}
require_once 'SmartCheckoutRates.php';
});
add_filter('woocommerce_shipping_methods', function ($methods) {
$methods['smartcheckout_shipping'] = 'SmartCheckoutRates';
return $methods;
});
include( CSC_PLUGIN_DIR . 'includes/functions.php' );
include( CSC_PLUGIN_DIR . 'includes/class-csc.php' );
include( CSC_PLUGIN_DIR . 'includes/smartcheckout/includes.php' );
}