1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit; |
2
|
|
|
/** |
3
|
|
|
* WP Shop Classic Checkout bootstrap file |
4
|
|
|
* @author Jérôme ALLEGRE - Eoxia dev team <[email protected]> |
5
|
|
|
* @version 0.1 |
6
|
|
|
* @package includes |
7
|
|
|
* @subpackage modules |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
if ( !class_exists("wps_classic_checkout") ) { |
12
|
|
|
|
13
|
|
|
/** Template Global vars **/ |
14
|
|
|
DEFINE('WPS_CLASSIC_CHECKOUT_DIR', basename(dirname(__FILE__))); |
15
|
|
|
DEFINE('WPS_CLASSIC_CHECKOUT_PATH', str_replace( "\\", "/", str_replace( WPS_CLASSIC_CHECKOUT_DIR, "", dirname( __FILE__ ) ) ) ); |
16
|
|
|
DEFINE('WPS_CLASSIC_CHECKOUT_URL', str_replace( str_replace( "\\", "/", ABSPATH), site_url() . '/', WPS_CLASSIC_CHECKOUT_PATH ) ); |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class wps_classic_checkout { |
20
|
|
|
/** |
21
|
|
|
* Define the main directory containing the template for the current plugin |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $template_dir; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Define the directory name for the module in order to check into frontend |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $plugin_dirname = WPS_CLASSIC_CHECKOUT_DIR; |
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
View Code Duplication |
function __construct() { |
|
|
|
|
34
|
|
|
/** Template Load **/ |
35
|
|
|
$this->template_dir = WPS_CLASSIC_CHECKOUT_PATH . WPS_CLASSIC_CHECKOUT_DIR . "/templates/"; |
36
|
|
|
|
37
|
|
|
/** Classic Checkout Shortcode **/ |
38
|
|
|
add_shortcode( 'wps_checkout', array( &$this, 'show_classic_checkout') ); |
39
|
|
|
add_shortcode( 'wpshop_checkout', array( &$this, 'show_classic_checkout') ); |
40
|
|
|
/** Checkout Step indicator **/ |
41
|
|
|
add_shortcode('wps_checkout_step_indicator', array(&$this, 'get_checkout_step_indicator') ); |
42
|
|
|
|
43
|
|
|
// Add scripts |
44
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
45
|
|
|
|
46
|
|
|
/** Ajax Actions **/ |
47
|
|
|
add_action( 'wp_ajax_wps-checkout_valid_step_three', array( &$this, 'wps_checkout_valid_step_three') ); |
48
|
|
|
add_action( 'wp_ajax_wps-checkout_valid_step_four', array( &$this, 'wps_checkout_valid_step_four') ); |
49
|
|
|
add_action( 'wp_ajax_wps-checkout_valid_step_five', array( &$this, 'wps_checkout_valid_step_five') ); |
50
|
|
|
|
51
|
|
|
add_action( 'admin_post_wps_direct_payment_link', array( 'wpshop_checkout', 'wps_direct_payment_link' ) ); |
52
|
|
|
add_action( 'admin_post_nopriv_wps_direct_payment_link', array( 'wpshop_checkout', 'wps_direct_payment_link_nopriv' ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Add scripts |
57
|
|
|
*/ |
58
|
|
|
function add_scripts() { |
|
|
|
|
59
|
|
|
wp_enqueue_script('jquery'); |
60
|
|
|
wp_enqueue_script( 'wps_classic_checkout', plugins_url('templates/frontend/js/wps_classic_checkout.js', __FILE__) ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Display Classic Checkout |
65
|
|
|
*/ |
66
|
|
|
function show_classic_checkout() { |
|
|
|
|
67
|
|
|
$order_id = !empty( $_GET['order_id'] ) ? (int) $_GET['order_id'] : ''; |
68
|
|
|
|
69
|
|
|
$wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
70
|
|
|
$current_step = !empty( $_GET[ 'order_step' ] ) && is_int( (int)$_GET[ 'order_step' ] ) ? (int)$_GET[ 'order_step' ] : null; |
71
|
|
|
|
72
|
|
|
/** Cas spécial lorsqu'il n'y a qu'un seul produit autorisé dans le panier / Special case when there is only one product allowed into cart */ |
73
|
|
|
if ( ( empty( $current_step ) || ( 1 == $current_step ) ) && ( !empty( $wpshop_cart_option ) && !empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) && ( 1 == $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) ) ) { |
74
|
|
|
if( empty($_SESSION) || empty($_SESSION['cart']) || empty($_SESSION['cart']['order_items']) ) { |
75
|
|
|
$product_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_product_page_id' ) ); |
76
|
|
|
$url = get_permalink( $product_page_id ); |
77
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
78
|
|
|
} |
79
|
|
|
else { |
80
|
|
|
$current_step = 2; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$checkout_step_indicator = do_shortcode( '[wps_checkout_step_indicator]'); |
85
|
|
|
$checkout_content = ''; |
86
|
|
|
|
87
|
|
|
if ( !empty($current_step) ) { |
88
|
|
|
switch( $current_step) { |
89
|
|
View Code Duplication |
case 1 : |
|
|
|
|
90
|
|
|
ob_start(); |
91
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one") ); |
92
|
|
|
$checkout_content .= ob_get_contents(); |
93
|
|
|
ob_end_clean(); |
94
|
|
|
break; |
95
|
|
|
case 2 : |
96
|
|
|
if ( get_current_user_id() != 0 ) { |
97
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
98
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
99
|
|
|
$url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
100
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
101
|
|
|
} |
102
|
|
|
else { |
103
|
|
|
ob_start(); |
104
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-two") ); |
105
|
|
|
$checkout_content .= ob_get_contents(); |
106
|
|
|
ob_end_clean(); |
107
|
|
|
} |
108
|
|
|
break; |
109
|
|
|
case 3 : |
110
|
|
|
if ( get_current_user_id() == 0 ) { |
111
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
112
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
113
|
|
|
$url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=2'; |
114
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
115
|
|
|
} |
116
|
|
|
else { |
117
|
|
|
if( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
118
|
|
|
ob_start(); |
119
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-three") ); |
120
|
|
|
$checkout_content .= ob_get_contents(); |
121
|
|
|
ob_end_clean(); |
122
|
|
|
$url = apply_filters('wps_extra_signup_actions', ( isset( $url ) ? $url : '' ) ); |
123
|
|
|
if(!empty($url)) { |
124
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
View Code Duplication |
else { |
|
|
|
|
128
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
129
|
|
|
$url = get_permalink( $checkout_page_id ); |
130
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
break; |
134
|
|
|
case 4 : |
135
|
|
|
if ( get_current_user_id() == 0 ) { |
136
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
137
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
138
|
|
|
$url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=2'; |
139
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
140
|
|
|
} |
141
|
|
|
else { |
142
|
|
|
if( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
143
|
|
|
ob_start(); |
144
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-four") ); |
145
|
|
|
$checkout_content .= ob_get_contents(); |
146
|
|
|
ob_end_clean(); |
147
|
|
|
} |
148
|
|
View Code Duplication |
else { |
|
|
|
|
149
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
150
|
|
|
$url = get_permalink( $checkout_page_id ); |
151
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
break; |
155
|
|
|
case 5 : |
156
|
|
|
if ( get_current_user_id() == 0 ) { |
157
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
158
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
159
|
|
|
$url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=2'; |
160
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
161
|
|
|
} |
162
|
|
|
else { |
163
|
|
|
$wps_cart = new wps_cart(); |
164
|
|
|
$order = $wps_cart->calcul_cart_information( array() ); |
165
|
|
|
$wps_cart->store_cart_in_session($order); |
166
|
|
|
$shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
167
|
|
|
if ( !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && ( ( !empty($shipping_option) && !empty($shipping_option['activate']) && !empty($_SESSION['shipping_method']) ) || ( !empty($shipping_option) && empty($shipping_option['activate']) ) ) ) { |
168
|
|
|
$order_id = ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
169
|
|
|
ob_start(); |
170
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-five") ); |
171
|
|
|
$checkout_content .= ob_get_contents(); |
172
|
|
|
ob_end_clean(); |
173
|
|
|
$checkout_content = apply_filters( 'classic_checkout_step_six_extra_content', $checkout_content ); |
|
|
|
|
174
|
|
|
} |
175
|
|
View Code Duplication |
else { |
|
|
|
|
176
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
177
|
|
|
$url = get_permalink( $checkout_page_id ); |
178
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
break; |
182
|
|
|
case 6 : |
183
|
|
|
|
184
|
|
|
if ( !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ){ |
185
|
|
|
$wps_marketing_tools_ctr = new wps_marketing_tools_ctr(); |
186
|
|
|
$checkout_content .= $wps_marketing_tools_ctr->display_ecommerce_ga_tracker( $_SESSION['order_id'] ); |
187
|
|
|
$checkout_content .= $this->wps_classic_confirmation_message(); |
188
|
|
|
$checkout_content .= $this->wps_summary_order(); |
189
|
|
|
} |
190
|
|
View Code Duplication |
else { |
|
|
|
|
191
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
192
|
|
|
$url = get_permalink( $checkout_page_id ); |
193
|
|
|
wpshop_tools::wpshop_safe_redirect( $url ); |
194
|
|
|
} |
195
|
|
|
break; |
196
|
|
View Code Duplication |
default : |
|
|
|
|
197
|
|
|
ob_start(); |
198
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one") ); |
199
|
|
|
$checkout_content .= ob_get_contents(); |
200
|
|
|
ob_end_clean(); |
201
|
|
|
break; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
} |
205
|
|
|
else { |
206
|
|
|
$checkout_content = do_shortcode('[wps_cart]'); |
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
require_once( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic_checkout") ); |
210
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Display the Step 6 confirmation message |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
function wps_classic_confirmation_message() { |
|
|
|
|
218
|
|
|
$output = ''; |
219
|
|
|
$wps_cart = new wps_cart(); |
220
|
|
|
$available_templates = array( 'banktransfer', 'checks', 'free', 'paypal', 'cic', 'quotation', 'cash_on_delivery' ); |
221
|
|
|
$payment_method = ( !empty($_SESSION['payment_method']) && in_array($_SESSION['payment_method'], $available_templates) ) ? $_SESSION['payment_method'] : 'others'; |
222
|
|
|
ob_start(); |
223
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir,"frontend", "confirmation/confirmation", $payment_method) ); |
224
|
|
|
$output .= ob_get_contents(); |
225
|
|
|
ob_end_clean(); |
226
|
|
|
return $output; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
function wps_summary_order() { |
|
|
|
|
230
|
|
|
ob_start(); |
231
|
|
|
require( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir,"frontend", "confirmation/confirmation-summary") ); |
232
|
|
|
$output = ob_get_contents(); |
233
|
|
|
ob_end_clean(); |
234
|
|
|
return $output; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Display Checkout Step indicator |
239
|
|
|
* @return String |
240
|
|
|
*/ |
241
|
|
|
function get_checkout_step_indicator() { |
|
|
|
|
242
|
|
|
$default_step = ( !empty( $_GET['order_step'] ) ) ? wpshop_tools::varSanitizer( $_GET['order_step'] ) : 1; |
|
|
|
|
243
|
|
|
$steps = array(); |
244
|
|
|
|
245
|
|
|
$shipping_address_option = get_option( 'wpshop_shipping_address_choice' ); |
246
|
|
|
$wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
247
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
|
|
|
|
248
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
|
|
|
249
|
|
|
|
250
|
|
|
|
251
|
|
|
$no_cart = false; |
|
|
|
|
252
|
|
|
if ( empty( $wpshop_cart_option ) || empty( $wpshop_cart_option[ 'total_nb_of_item_allowed' ] ) || ( 1 != (int) $wpshop_cart_option[ 'total_nb_of_item_allowed' ][0] ) ) { |
253
|
|
|
$steps[] = __('Cart', 'wpshop'); |
254
|
|
|
} |
255
|
|
|
else { |
256
|
|
|
$no_cart = true; |
|
|
|
|
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$steps[] = __('Identification', 'wpshop'); |
260
|
|
|
$steps[] = __('Addresses', 'wpshop'); |
261
|
|
|
|
262
|
|
|
$no_shipping = false; |
|
|
|
|
263
|
|
|
if ( !empty( $shipping_address_option ) && !empty( $shipping_address_option[ 'activate' ] ) && !empty( $shipping_address_option[ 'choice' ] ) ) { |
264
|
|
|
$steps[] = __('Shipping Mode', 'wpshop'); |
265
|
|
|
} |
266
|
|
|
else { |
267
|
|
|
$no_shipping = true; |
|
|
|
|
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$no_payment = false; |
|
|
|
|
271
|
|
|
$partial_payment_for_quotation = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
|
|
|
|
272
|
|
|
if( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && ( ( !empty($_SESSION['cart']['order_amount_to_pay_now']) && number_format( $_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '' ) == '0.00' ) || ( !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' && isset( $partial_payment_for_quotation['for_quotation']['activate'] ) ) ) ) { |
273
|
|
|
$no_payment = true; |
|
|
|
|
274
|
|
|
} |
275
|
|
|
else { |
276
|
|
|
$steps[] = __('Payment', 'wpshop'); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
$steps[] = __('Confirmation', 'wpshop'); |
280
|
|
|
|
281
|
|
|
$steps = apply_filters('wps_extra_action_checkout_indicator', $steps); |
|
|
|
|
282
|
|
|
|
283
|
|
|
require_once( wpshop_tools::get_template_part( WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir,"frontend", "checkout_step_indicator/checkout_step_indicator") ); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* AJAX - Valid Checkout Step three |
288
|
|
|
*/ |
289
|
|
|
function wps_checkout_valid_step_three() { |
|
|
|
|
290
|
|
|
$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
291
|
|
|
|
292
|
|
|
if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_valid_step_three' ) ) |
293
|
|
|
wp_die(); |
294
|
|
|
|
295
|
|
|
$response = ''; $status = true; |
|
|
|
|
296
|
|
|
|
297
|
|
|
$shipping_address = ( !empty($_POST['shipping_address_id']) ) ? wpshop_tools::varSanitizer( $_POST['shipping_address_id'] ): null; |
298
|
|
|
$billing_address = ( !empty($_POST['billing_address_id']) ) ? wpshop_tools::varSanitizer( $_POST['billing_address_id'] ): null; |
299
|
|
|
|
300
|
|
|
$user_id = get_current_user_id(); |
301
|
|
|
|
302
|
|
|
$response = '<div class="wps-alert-error"><ul>'; |
303
|
|
|
|
304
|
|
|
if( $user_id != 0 ) { |
305
|
|
|
$shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
306
|
|
|
$billing_option = get_option( 'wpshop_billing_address' ); |
307
|
|
|
$user_addresses = wps_address::get_addresses_list( $user_id ); |
308
|
|
|
|
309
|
|
|
// Check if is only downloadable else display address |
310
|
|
|
$cart_is_downloadable = false; |
311
|
|
|
if ( !empty( $_SESSION['cart'] ) && !empty( $_SESSION['cart']['order_items'] ) ) { |
312
|
|
|
foreach( $_SESSION['cart']['order_items'] as $c ) { |
313
|
|
|
$product = wpshop_products::get_product_data( $c['item_id'] ); |
314
|
|
|
/** Check if it's a variation and check the parent product **/ |
315
|
|
|
if ( get_post_type( $c['item_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
316
|
|
|
$parent_def = wpshop_products::get_parent_variation( $c['item_id'] ); |
317
|
|
|
if ( !empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_']) ) { |
318
|
|
|
$product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_']; |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
if( !empty($product['is_downloadable_']) && ( __( $product['is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $product['is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
322
|
|
|
$cart_is_downloadable = true; |
323
|
|
|
} else { |
324
|
|
|
$cart_is_downloadable = false; |
325
|
|
|
break; |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
if( !empty($shipping_option) && !empty($shipping_option['activate']) && !$cart_is_downloadable ) { |
331
|
|
|
/** Check Shipping address **/ |
332
|
|
View Code Duplication |
if ( empty($shipping_address) ) { |
|
|
|
|
333
|
|
|
$status = false; |
334
|
|
|
/** Check if user have already create a shipping address **/ |
335
|
|
|
if ( !empty($shipping_option['choice']) && !empty($user_addresses) && !empty($user_addresses[ $shipping_option['choice'] ]) ){ |
336
|
|
|
$response .= '<li>'.__( 'You must select a shipping address', 'wpshop' ).'</li>'; |
337
|
|
|
} |
338
|
|
|
else { |
339
|
|
|
$response .= '<li>'.__( 'You must create a shipping address', 'wpshop' ).'</li>'; |
340
|
|
|
} |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
} |
344
|
|
|
/** Check Billing address **/ |
345
|
|
View Code Duplication |
if( empty($billing_address) ) { |
|
|
|
|
346
|
|
|
$status = false; |
347
|
|
|
if ( !empty($billing_option['choice']) && !empty($user_addresses) && !empty($user_addresses[ $billing_option['choice'] ]) ){ |
348
|
|
|
$response .= '<li>'.__( 'You must select a billing address', 'wpshop' ).'</li>'; |
349
|
|
|
} |
350
|
|
|
else { |
351
|
|
|
$response .= '<li>'.__( 'You must create a billing address', 'wpshop' ).'</li>'; |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
else { |
356
|
|
|
$status = false; |
357
|
|
|
$response .= '<li>'.__( 'You must be logged to pass to next step', 'wpshop' ).'</li>'; |
358
|
|
|
} |
359
|
|
|
$response .= '</ul></div>'; |
360
|
|
|
|
361
|
|
|
/** If no error **/ |
362
|
|
|
if( $status ) { |
363
|
|
|
$_SESSION['shipping_address'] = $shipping_address; |
364
|
|
|
$_SESSION['billing_address'] = $billing_address; |
365
|
|
|
|
366
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
367
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
368
|
|
|
/** Checking if no shipping method is required and it is a quotation or a free order **/ |
369
|
|
|
$shipping_option = get_option( 'wps_shipping_mode' ); |
370
|
|
|
|
371
|
|
|
/** Quotation, no shipping, no payment */ |
372
|
|
|
if ( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
373
|
|
|
$status = true; |
374
|
|
|
$_SESSION['shipping_method'] = 'No Shipping method required'; |
375
|
|
|
$payment_method = $_SESSION['payment_method'] = 'quotation'; |
376
|
|
|
$order_id = wpshop_checkout::process_checkout( $payment_method, ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
|
|
|
377
|
|
|
$response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
378
|
|
|
} else { |
379
|
|
|
$available_shipping_method = false; |
380
|
|
|
if( !empty($shipping_option) && !empty($shipping_option['modes']) && !$cart_is_downloadable ) { |
|
|
|
|
381
|
|
|
foreach( $shipping_option['modes'] as $shipping_mode_id => $shipping_mode ) { |
|
|
|
|
382
|
|
|
if( !empty($shipping_mode['active']) && $shipping_mode['active'] == 'on' ) { |
383
|
|
|
$available_shipping_method = true; |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
if( !$available_shipping_method ) { |
389
|
|
|
$_SESSION['shipping_method'] = 'No Shipping method required'; |
390
|
|
|
$order_id = ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
391
|
|
|
|
392
|
|
|
if( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && isset($_SESSION['cart']['order_amount_to_pay_now']) && number_format( $_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '' ) == '0.00' ) { |
393
|
|
|
$status = true; |
394
|
|
|
$payment_method = $_SESSION['payment_method'] = 'free'; |
395
|
|
|
$order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
|
|
|
396
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
397
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
398
|
|
|
$url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
399
|
|
|
// wpshop_tools::wpshop_safe_redirect( $url ); |
|
|
|
|
400
|
|
|
$response = $url; |
401
|
|
|
} |
402
|
|
View Code Duplication |
else { |
|
|
|
|
403
|
|
|
$status = true; |
404
|
|
|
$response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=5'; |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
View Code Duplication |
else { |
|
|
|
|
408
|
|
|
$status = true; |
409
|
|
|
$response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=4'; |
410
|
|
|
} |
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
//Stock checking verification |
414
|
|
|
$this->checking_stock(); |
415
|
|
|
|
416
|
|
|
wp_die( json_encode( array( 'status' => $status, 'response' => $response ) ) ); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* AJAX - Valid Checkout step four |
421
|
|
|
*/ |
422
|
|
|
function wps_checkout_valid_step_four() { |
|
|
|
|
423
|
|
|
$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
424
|
|
|
|
425
|
|
|
if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_valid_step_four' ) ) |
426
|
|
|
wp_die(); |
427
|
|
|
|
428
|
|
|
$shipping_method = ( !empty($_POST['shipping_mode']) ) ? wpshop_tools::varSanitizer($_POST['shipping_mode']) : null; |
429
|
|
|
$status = false; |
430
|
|
|
$response = ''; |
431
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
432
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
433
|
|
|
if ( !empty($shipping_method) ) { |
434
|
|
|
$status = true; |
435
|
|
|
$_SESSION['shipping_method'] = $shipping_method; |
436
|
|
|
$order_id = ( !empty($_SESSION['cart']['order_id']) ) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; |
437
|
|
|
if ( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { |
438
|
|
|
$partial_payment_for_quotation = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
|
|
|
|
439
|
|
|
if( isset( $partial_payment_for_quotation['for_quotation']['activate'] ) ) { |
440
|
|
|
$step = '5'; |
441
|
|
|
} else { |
442
|
|
|
$payment_method = $_SESSION['payment_method'] = 'quotation'; |
443
|
|
|
$order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
|
|
|
444
|
|
|
$step = '6'; |
445
|
|
|
} |
446
|
|
|
$response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
447
|
|
|
} |
448
|
|
|
elseif( !empty($_SESSION) && !empty( $_SESSION['cart'] ) && !empty($_SESSION['cart']['order_amount_to_pay_now']) && number_format( $_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '' ) == '0.00' ) { |
449
|
|
|
$payment_method = $_SESSION['payment_method'] = 'free'; |
450
|
|
|
$order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
|
|
|
|
451
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
452
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
453
|
|
|
$url = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
454
|
|
|
$response = $url; |
455
|
|
|
} |
456
|
|
View Code Duplication |
else { |
|
|
|
|
457
|
|
|
$response = get_permalink( wpshop_tools::get_page_id( $checkout_page_id ) ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=5'; |
458
|
|
|
} |
459
|
|
|
} |
460
|
|
|
else { |
461
|
|
|
$response .= '<div class="wps-alert-error">'.__( 'You must select a shipping method', 'wpshop' ).'</div>'; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
//Stock checking verification |
465
|
|
|
$this->checking_stock(); |
466
|
|
|
|
467
|
|
|
echo json_encode( array( 'status' => $status, 'response' => $response) ); |
468
|
|
|
die(); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* AJAX - Valid Checkout step four |
473
|
|
|
*/ |
474
|
|
|
function wps_checkout_valid_step_five() { |
|
|
|
|
475
|
|
|
$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
476
|
|
|
if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_valid_step_five' ) ) |
477
|
|
|
wp_die(); |
478
|
|
|
|
479
|
|
|
$status = false; |
480
|
|
|
$response = ''; |
|
|
|
|
481
|
|
|
$payment_method = ( !empty($_POST['wps-payment-method']) ) ? wpshop_tools::varSanitizer( $_POST['wps-payment-method'] ): null; |
482
|
|
|
$order_id = ( !empty($_SESSION['cart']['order_id']) ) ? (int) $_SESSION['cart']['order_id'] : 0; |
483
|
|
|
$customer_comment = ( !empty($_POST['wps-customer-comment']) ) ? wpshop_tools::varSanitizer( $_POST['wps-customer-comment'] ) : null; |
484
|
|
|
|
485
|
|
|
$terms_of_sale_required = isset( $_POST['terms_of_sale_indicator'] ) && !empty( $_POST['terms_of_sale_indicator'] ) ? (bool)$_POST['terms_of_sale_indicator'] : (bool)false; |
486
|
|
|
$terms_of_sale_checked = isset( $_POST['terms_of_sale'] ) && !empty( $_POST['terms_of_sale'] ) ? (bool)$_POST['terms_of_sale_indicator'] : (bool)false; |
487
|
|
|
|
488
|
|
|
if ( ( $terms_of_sale_required && $terms_of_sale_checked ) || !$terms_of_sale_required ) { |
489
|
|
|
if ( !empty($payment_method) ) { |
490
|
|
|
/** Check if the payment method exist for the shop **/ |
491
|
|
|
$payment_option = get_option( 'wps_payment_mode' ); |
492
|
|
|
|
493
|
|
|
if( !empty($payment_option) && !empty($payment_option['mode']) && array_key_exists( $payment_method, $payment_option['mode']) && !empty($payment_option['mode'][$payment_method]['active']) ) { |
494
|
|
|
if( !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation' ) { |
495
|
|
|
$new_payment_method = $payment_method; |
496
|
|
|
$payment_method = 'quotation'; |
497
|
|
|
$is_quotation = true; |
498
|
|
|
} else { |
499
|
|
|
$is_quotation = false; |
500
|
|
|
} |
501
|
|
|
$order_id = wpshop_checkout::process_checkout( $payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address'] ); |
502
|
|
|
if( !empty($order_id) && !empty($customer_comment) ) { |
503
|
|
|
$wps_back_office_orders_mdl = new wps_back_office_orders_mdl(); |
504
|
|
|
$wps_back_office_orders_mdl->add_private_comment($order_id, $customer_comment); |
505
|
|
|
//wp_update_post( array('ID' => $order_id, 'post_excerpt' => $customer_comment) ); |
|
|
|
|
506
|
|
|
} |
507
|
|
|
$permalink_option = get_option( 'permalink_structure' ); |
508
|
|
|
$checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
509
|
|
|
$response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=6'; |
510
|
|
|
if( $is_quotation ) { |
511
|
|
|
$order_meta = get_post_meta( $order_id, '_order_postmeta', true ); |
512
|
|
|
$params = array( 'method' => $new_payment_method, 'waited_amount' => $order_meta['order_partial_payment'], 'status' => 'waiting_payment', 'author' => get_current_user_id() ); |
|
|
|
|
513
|
|
|
$order_meta['order_payment']['received'][0] = $params; |
514
|
|
|
update_post_meta( $order_id, '_order_postmeta', $order_meta ); |
515
|
|
|
$_SESSION['payment_method'] = $new_payment_method; |
516
|
|
|
} else { |
517
|
|
|
$_SESSION['payment_method'] = $payment_method; |
518
|
|
|
} |
519
|
|
|
$status = true; |
520
|
|
|
//Add an action to extra actions on order save |
521
|
|
|
// @TODO : REQUEST |
522
|
|
|
$args = array( 'order_id' => $order_id, 'posted_data' => $_REQUEST); |
523
|
|
|
wpshop_tools::create_custom_hook( 'wps_order_extra_save_action', $args ); |
524
|
|
|
} |
525
|
|
|
else { |
526
|
|
|
$response = '<div class="wps-alert-error">' .__( 'This payment method is unavailable', 'wpshop' ).'</div>'; |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
else { |
530
|
|
|
$response = '<div class="wps-alert-error">' .__( 'You must choose a payment method', 'wpshop' ).'</div>'; |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
else { |
534
|
|
|
$response = '<div class="wps-alert-error">' .__( 'You must accept the terms of sale to order', 'wpshop' ).'</div>'; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
echo json_encode( array('status' => $status, 'response' => $response) ); |
538
|
|
|
die(); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* Checking stock in differents checkout steps |
543
|
|
|
*/ |
544
|
|
|
function checking_stock() { |
|
|
|
|
545
|
|
|
if( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
546
|
|
|
foreach( $_SESSION['cart']['order_items'] as $item_id => $item ) { |
547
|
|
|
$wps_product = new wps_product_ctr(); |
548
|
|
|
$checking = $wps_product->check_stock( $item['item_id'], $item['item_qty'], $item_id ); |
549
|
|
|
if( $checking !== true ) { |
550
|
|
|
unset( $_SESSION['cart']['order_items'][$item_id] ); |
551
|
|
|
$wps_cart_ctr = new wps_cart(); |
552
|
|
|
$order = $wps_cart_ctr->calcul_cart_information( array() ); |
553
|
|
|
$wps_cart_ctr->store_cart_in_session( $order ); |
554
|
|
|
} |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
} |
560
|
|
|
} |
561
|
|
|
if ( class_exists("wps_classic_checkout") ) { |
562
|
|
|
$wps_classic_checkout = new wps_classic_checkout(); |
563
|
|
|
} |
564
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.