-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpd-ecommerce.php
249 lines (214 loc) · 8.34 KB
/
wpd-ecommerce.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/**
* The plugin bootstrap file
*
* @package WPD_eCommerce
* @author CannaBiz Software <contact@cannabizsoftware.com>
* @license GPL-2.0+
* @link https://cannabizsoftware.com
* @since 1.0.0
*
* Plugin Name: CannaBiz eCommerce
* Plugin URI: https://cannabizsoftware.com/product/ecommerce
* Description: Adds eCommerce capabilities to CannaBiz Software's menu management plugin.
* Version: 2.3.0
* Author: CannaBiz Software
* Author URI: https://cannabizsoftware.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wpd-ecommerce
* Domain Path: /languages
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
wp_die();
}
// Development mode.
define( 'DEV', false );
/**
* CannaBiz eCommerce
*
* @since 1.0
* @return void
*/
function wpd_ecommerce() {
/**
* Access all settings
*/
$wpd_settings = get_option( 'wpdas_general' );
//print_r( $wpd_settings );
// Define sales tax (if any).
if ( ! isset( $wpd_settings['wpd_ecommerce_sales_tax'] ) || '' == $wpd_settings['wpd_ecommerce_sales_tax'] ) {
define( 'SALES_TAX', null );
} else {
// Create sales tax.
$sales_tax = $wpd_settings['wpd_ecommerce_sales_tax'] * 0.01;
// Define sales tax.
define( 'SALES_TAX', $sales_tax );
}
// Define excise tax (if any).
if ( ! isset( $wpd_settings['wpd_ecommerce_excise_tax'] ) || '' == $wpd_settings['wpd_ecommerce_excise_tax'] ) {
define( 'EXCISE_TAX', null );
} else {
// Create excise tax.
$excise_tax = $wpd_settings['wpd_ecommerce_excise_tax'] * 0.01;
// Define excise tax.
define( 'EXCISE_TAX', $excise_tax );
}
// Define currency code.
define( 'CURRENCY', wpd_currency_code() );
}
wpd_ecommerce();
/**
* Include add-ons directly
*
* @return void
*/
function wpd_ecommerce_include_addons() {
if ( ! function_exists( 'run_wpd_inventory' ) ) {
// Include inventory management.
include_once( dirname( __FILE__ ) . '/includes/extend/inventory/wpd-inventory.php' );
}
if ( ! function_exists( 'run_wpd_topsellers' ) ) {
// Include top sellers management.
include_once( dirname( __FILE__ ) . '/includes/extend/topsellers/wpd-topsellers.php' );
}
if ( ! function_exists( 'run_wpd_locations' ) ) {
// Include location management.
include_once( dirname( __FILE__ ) . '/includes/extend/locations/wpd-locations.php' );
}
if ( ! function_exists( 'run_wpd_heavyweights' ) ) {
// Include heavyweights management.
include_once( dirname( __FILE__ ) . '/includes/extend/heavyweights/wpd-heavyweights.php' );
}
if ( ! function_exists( 'run_wpd_styles' ) ) {
// Include styles.
include_once( dirname( __FILE__ ) . '/includes/extend/styles/wpd-styles.php' );
}
}
add_action( 'init', 'wpd_ecommerce_include_addons' );
// Includes for plugin activation.
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-activation.php' );
// Includes for Helper Functions.
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-sessions-functions.php' );
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-core-functions.php' );
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-admin-settings-functions.php' );
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-cart-functions.php' );
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-orders-functions.php' );
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-customers-functions.php' );
include_once( dirname( __FILE__ ) . '/includes/wpd-ecommerce-archive-items-functions.php' );
// Includes for Classes.
include_once( dirname( __FILE__ ) . '/classes/class-cart.php' );
include_once( dirname( __FILE__ ) . '/classes/class-item.php' );
include_once( dirname( __FILE__ ) . '/classes/class-csv-customer-export.php' );
// Includes for Cart.
include_once( dirname( __FILE__ ) . '/cart/cart-widget.php' );
include_once( dirname( __FILE__ ) . '/cart/cart-shortcode.php' );
// Includes for Checkout.
include_once( dirname( __FILE__ ) . '/checkout/checkout-shortcode.php' );
// Includes for Customers.
include_once( dirname( __FILE__) . '/customers/customer-account-details.php' );
include_once( dirname( __FILE__) . '/customers/customer-account-shortcode.php' );
// Includes for Orders.
include_once( dirname( __FILE__ ) . '/orders/orders-database.php' );
include_once( dirname( __FILE__ ) . '/orders/orders-post-type.php' );
include_once( dirname( __FILE__ ) . '/orders/orders-metaboxes.php' );
/**
* Add output buffering to help with checkout redirect.
*
* @return void
*/
function wpd_ecommerce_output_buffer() {
ob_start();
}
add_action( 'init', 'wpd_ecommerce_output_buffer' );
/**
* Load admin scripts and styles
*
* @since 1.0
* @return void
*/
function wpd_ecommerce_load_admin_scripts() {
wp_enqueue_style( 'wpd-ecommerce-admin', plugin_dir_url( __FILE__ ) . 'assets/css/wpd-ecommerce-admin.min.css' );
}
add_action( 'admin_enqueue_scripts', 'wpd_ecommerce_load_admin_scripts' );
/**
* Load public scripts and styles
*
* @since 1.0
* @return void
*/
function wpd_ecommerce_load_public_scripts() {
wp_enqueue_style( 'wpd-ecommerce-public', plugin_dir_url( __FILE__ ) . 'assets/css/wpd-ecommerce-public.min.css', array( 'wp-dispensary-font-awesome' ) );
wp_enqueue_script( 'wpd-ecommerce-public', plugin_dir_url( __FILE__ ) . 'assets/js/wpd-ecommerce-public.js', array( 'jquery' ), '2.3.0', false );
if ( isset( $_SESSION['wpd_ecommerce'] ) ) {
// Translation array data.
$translation_array = array(
'pageURL' => get_the_permalink(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'PAYMENT_TYPE_AMOUNT' => $_SESSION['wpd_ecommerce']->payment_type_amount,
'session_data' => $_SESSION['wpd_ecommerce']
);
} else {
// Translation array data.
$translation_array = array(
'pageURL' => get_the_permalink(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'PAYMENT_TYPE_AMOUNT' => '0',
'session_data' => ''
);
}
// Translation array filter.
$translation_array = apply_filters( 'wpd_ecommerce_localize_script_translation_array', $translation_array );
// Localize script.
wp_localize_script( 'wpd-ecommerce-public', 'object_name', $translation_array );
}
add_action( 'wp_enqueue_scripts', 'wpd_ecommerce_load_public_scripts' );
/**
* Custom Templates
*
* @param string $template_path
*
* @since 1.0
* @return string
*/
function wpd_ecommerce_include_template_function( $template_path ) {
// CannaBiz Menu products.
if ( 'products' === get_post_type() ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array( 'single-item.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) . '/templates/single-item.php';
}
} elseif ( is_archive() ) {
if ( $theme_file = locate_template( array( 'archive-items.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) . '/templates/archive-items.php';
}
}
}
// Orders templates.
if ( 'wpd_orders' === get_post_type() ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array ( 'single-order.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) . '/templates/single-order.php';
}
} elseif ( is_archive() ) {
if ( $theme_file = locate_template( array ( 'archive-orders.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) . '/templates/archive-orders.php';
}
}
}
return $template_path;
}
add_filter( 'template_include', 'wpd_ecommerce_include_template_function', 1 );