PluginProbe
MakeCommerce for WooCommerce / 2.6.2
MakeCommerce for WooCommerce v2.6.2
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
makecommerce / trunk / makecommerce-simplecheckout.php

makecommerce-simplecheckout.php in MakeCommerce for WooCommerce 2.6.2, at trunk/makecommerce-simplecheckout.php

571 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * SimpleCheckout functionality
5 */
6
7
8 function sc_return_trigger($vars) {
9 $vars[] = 'mc_cart_to_order';
10 $vars[] = 'mc_calculate_shipment';
11 $vars[] = 'mc_cart_update';
12 $vars[] = 'mc_cart_id';
13 $vars[] = 'mc_nonce';
14 $vars[] = 'lang1';
15 return $vars;
16 }
17 function sc_return_trigger_check() {
18 if (intval(get_query_var('mc_cart_to_order')) === 1) {
19 $cart_info = json_decode(file_get_contents('php://input'));
20
21 if (isset($_GET["lang1"])) {
22 $_GET["lang"]=$_GET["lang1"];
23 //set wpml language
24 if (function_exists('icl_object_id')) {
25 do_action('wpml_switch_language', $_GET["lang1"]);
26
27 } else {
28 //set polylang language
29 if (function_exists('pll_current_language')) {
30 //not implemented yet
31 }
32 }
33 }
34
35 global $wpdb;
36 $tmp_order = $wpdb->get_row("select content, order_id from {$wpdb->prefix}woocommerce_makecommerce_sc where cart_id = '{$cart_info->cartId}'");
37 if (!$tmp_order) {
38 error_log('no such cart');
39 echo json_encode(array('code' => -1));
40 exit;
41 }
42
43 //check for mitm manipulations
44 $tmp_order_sco_data = $wpdb->get_row("select content, order_id from {$wpdb->prefix}woocommerce_makecommerce_sc where cart_id = '{$cart_info->cartId}_provided_sco_data'");
45 if (!$tmp_order_sco_data) {
46 error_log('Missing sco provided data for cart');
47 echo json_encode(array('code' => -1));
48 exit;
49 } else {
50 $matching_shipment_method_found = false;
51 $provided_cart_data = json_decode($tmp_order_sco_data->content);
52
53 if (!empty($provided_cart_data->shipmentMethods)) {
54 foreach ($provided_cart_data->shipmentMethods as $p_shipment_method) {
55 //check to see if the selected shipment has a matching cart id and amount.
56 if ($p_shipment_method->methodId == $cart_info->shipmentMethod->methodId && $p_shipment_method->amount == $cart_info->shipmentMethod->amount) {
57 $matching_shipment_method_found = true;
58 }
59 }
60 } else { //no shipment methods. Most likely a virtual product
61 $matching_shipment_method_found = true;
62 }
63
64 //response option does not match with provided sco data options. Either something went terribly wrong or someone manipulated with the data. Cancel payment
65 if (!$matching_shipment_method_found) {
66 error_log('Cart shipping method with matching price not found in sco_provided_data');
67 header("HTTP/1.1 400 Bad Request");
68 exit;
69 }
70
71 }
72
73 $free_shipping = false;
74
75 $tmp_cart = new WC_Cart();
76 $tmp_order->content = json_decode($tmp_order->content);
77 $content = !empty($tmp_order->content->order) ? $tmp_order->content->order : $tmp_order->content;
78 $coupons = !empty($tmp_order->content->coupons) ? $tmp_order->content->coupons : array();
79 foreach ($content as $item_row) {
80 $tmp_cart->add_to_cart($item_row->id, $item_row->qty);
81 }
82 if ($tmp_order->order_id) {
83 $order = new WC_Order($tmp_order->order_id);
84 } else {
85 $order = wc_create_order();
86 foreach ($content as $item_row) {
87 $product_id = !empty($item_row->var) ? $item_row->var : $item_row->id;
88 if (function_exists('wc_get_product')) {
89 $item_id = $order->add_product(wc_get_product($product_id), $item_row->qty);
90 } else {
91 $item_id = $order->add_product(get_product($product_id), $item_row->qty);
92 }
93 }
94 $order->calculate_totals();
95 $free_shipping = 0;
96 foreach ($coupons as $coupon) {
97 $coupon = new WC_Coupon($coupon);
98 $amount = $coupon->get_amount();
99 if ($coupon->is_type('percent')) {
100 $amount = $order->get_total() / 100 * $amount;
101 }
102 if (method_exists($order, 'add_item')) {
103 $item = new WC_Order_Item_Coupon();
104 $item->set_props(array(
105 'code' => $coupon->get_code(),
106 'discount' => $amount,
107 'discount_tax' => 0
108 ));
109 $order->add_item($item);
110 } else {
111 //$order->add_code($coupon->get_code(), $amount);
112 }
113 if ((method_exists($coupon, 'get_free_shipping') && $coupon->get_free_shipping()) || $coupon->free_shipping) { $free_shipping = true; }
114 }
115 }
116 $payment_method = new woocommerce_makecommerce();
117 $order->set_payment_method($payment_method);
118 $billing_address = array(
119 'first_name' => $cart_info->customer->firstname,
120 'last_name' => $cart_info->customer->lastname,
121 'email' => $cart_info->customer->email,
122 'phone' => $cart_info->customer->phone,
123 );
124
125 $shipping_address = $billing_address;
126 $shipment_method = false;
127 if (!empty($cart_info->invoiceAddress)) {
128 $invoice = $cart_info->invoiceAddress;
129 $billing_address['company'] = '';
130 if (!empty($invoice->firstname)) { $billing_address['first_name'] = $invoice->firstname; }
131 if (!empty($invoice->lastname)) { $billing_address['last_name'] = $invoice->lastname; }
132 if (!empty($invoice->country)) { $billing_address['country'] = $invoice->country; }
133 if (!empty($invoice->county)) { $billing_address['state'] = $invoice->county; }
134 if (!empty($invoice->city)) { $billing_address['city'] = $invoice->city; }
135 if (!empty($invoice->street1)) { $billing_address['address_1'] = $invoice->street1; }
136 if (!empty($invoice->street2)) { $billing_address['address_2'] = $invoice->street2; }
137 if (!empty($invoice->postalCode)) { $billing_address['postcode'] = $invoice->postalCode; }
138 if (!empty($invoice->legalName)) { $billing_address['company'] .= $invoice->legalName; }
139 if (!empty($invoice->registryCode)) { $billing_address['company'] .= ' ' . $invoice->registryCode; }
140 if (!empty($invoice->vatNum)) { $billing_address['company'] .= ' ' . $invoice->vatNum; }
141 }
142 if (!empty($cart_info->shipmentAddress)) {
143 $shipment = $cart_info->shipmentAddress;
144 if (!empty($shipment->country)) { $shipment_address['country'] = $shipment->country; }
145 if (!empty($shipment->county)) { $shipment_address['state'] = $shipment->county; }
146 if (!empty($shipment->city)) { $shipment_address['city'] = $shipment->city; }
147 if (!empty($shipment->street1)) { $shipment_address['address_1'] = $shipment->street1; }
148 if (!empty($shipment->street2)) { $shipment_address['address_2'] = $shipment->street2; }
149 if (!empty($shipment->postalCode)) { $shipment_address['postcode'] = $shipment->postalCode; }
150 if (!empty($shipment->firstname)) { $shipment_address['first_name'] = $shipment->firstname; }
151 if (!empty($shipment->lastname)) { $shipment_address['last_name'] = $shipment->lastname; }
152 }
153 if (!empty($cart_info->shipmentMethod)) {
154 $shipment_details = $cart_info->shipmentMethod;
155 $zones = WC_Shipping_Zones::get_zones();
156 $continents = WC()->countries->get_continents();
157 $supported_methods = array('parcelmachine_omniva' => 'APT', 'parcelmachine_smartpost' => 'APT', 'parcelmachine_dpd' => 'APT', 'courier_omniva' => 'COU', 'courier_smartpost' => 'COU', 'local_pickup' => 'OTH', 'flat_rate' => 'COU');
158 foreach ($zones as $zone) {
159 if ($shipment_method) { continue; }
160 foreach ($zone['shipping_methods'] as $method) {
161 if ($shipment_method) { continue; }
162 if (empty($supported_methods[$method->id])) { continue; }
163 if ($supported_methods[$method->id] === $shipment_details->type && (empty($shipment_details->carrier) || strtoupper($method->carrier) === $shipment_details->carrier)) {
164 foreach ($zone['zone_locations'] as $location) {
165 if ($location->type === 'continent' && !empty($continents[$location->code])) {
166 if (in_array($shipment->country, $continents[$location->code]['countries'])) {
167 $shipment_method = $method;
168 }
169 } else if ($location->type === 'state') {
170 list($country, $state) = explode(':', $location->code);
171 if ($country === $shipment->country) {
172 $shipment_method = $method;
173 }
174 } else if ($shipment->country === $location->code) {
175 $shipment_method = $method;
176 }
177 }
178 }
179 }
180 }
181 }
182 $order->set_address($billing_address, 'billing');
183 if (empty($shipment_address)) {
184 $order->set_address($billing_address, 'shipping');
185 } else {
186 $order->set_address($shipment_address, 'shipping');
187 }
188 $order->remove_order_items('shipping');
189 if ($shipment_method) {
190 $package = $tmp_cart->get_shipping_packages();
191 if (!empty($package)) { $package = $package[0]; }
192 $price_int = $shipment_method->get_rates_for_package($package);
193 $price_int = get_rate_without_taxes($shipment_method->id.':'.$shipment_method->instance_id, $price_int);
194 $price = !empty($cart_info->shipmentMethod->amount) ? (double)$cart_info->shipmentMethod->amount : 0;
195 if ($free_shipping) $price = $price_int = 0;
196 $rate = new WC_Shipping_Rate($shipment_method->id.':'.$shipment_method->instance_id, !empty($shipment_method->name_ext) ? $shipment_method->name_ext : $shipment_method->title, $price_int, array(), $shipment_method->id.':'.$shipment_method->instance_id);
197 if (class_exists('WC_Order_Item_Shipping')) {
198 $item = new WC_Order_Item_Shipping();
199 $item->set_order_id($order->get_id());
200 $item->set_shipping_rate($rate);
201 $shipping_id = $item->save();
202 } else {
203 $order->add_shipping($rate);
204 }
205 if (!empty($shipment_method->type) && $shipment_method->type === 'apt') {
206 $machine = mk_get_machine(strtolower($shipment_method->carrier), $shipment->destinationId);
207 if ($machine) {
208 update_post_meta($order->get_id(), '_shipping_first_name', get_post_meta($order->get_id(), '_billing_first_name', true));
209 update_post_meta($order->get_id(), '_shipping_last_name', get_post_meta($order->get_id(), '_billing_last_name', true));
210 update_post_meta($order->get_id(), '_shipping_address_1', sanitize_text_field($machine['name']));
211 update_post_meta($order->get_id(), '_shipping_address_2', sanitize_text_field($machine['address']));
212 update_post_meta($order->get_id(), '_shipping_city', sanitize_text_field($machine['city']));
213 update_post_meta($order->get_id(), '_shipping_postcode', '');
214 update_post_meta($order->get_id(), '_parcel_machine', strtolower($shipment_method->carrier).'||'.$shipment->destinationId);
215 }
216 }
217 }
218 update_post_meta($order->get_id(), '_makecommerce_sc_cart_id', $cart_info->cartId);
219
220 $order->calculate_totals();
221 if (!empty($tmp_order->content->discount)) { $order->set_discount_total($tmp_order->content->discount); }
222 if (!empty($tmp_order->content->discount_tax)) { $order->set_discount_tax($tmp_order->content->discount_tax); }
223 $order->set_total($order->get_total() - ($order->get_discount_total() + $order->get_discount_tax()));
224 $order->save();
225 $wpdb->update($wpdb->prefix.'woocommerce_makecommerce_sc', array('status' => 1, 'order_id' => $order->get_id(), 'modified' => time()), array('cart_id' => $cart_info->cartId));
226
227 if (isset($_GET["lang1"])) {
228 $locale=$_GET["lang1"];
229 } else {
230 $locale = get_locale();
231 if ($locale) { $locale = explode('_', $locale); $locale = !empty($locale[1]) ? strtolower($locale[1]) : strtolower($locale[0]); }
232 $locale = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $locale;
233 }
234
235 //locale has to be 2 chars:
236 $locale = substr($locale, 0, 2);
237
238 $response = array(
239 'cartId' => $cart_info->cartId,
240 'reference' => (string)$order->get_id(),
241 'locale' => $locale,
242 'transactionUrl' => array(
243 'returnUrl' => array(
244 'url' => site_url('/?mc_cart_update=1&lang1='.$locale),
245 'method' => 'POST'
246 ),
247 'cancelUrl' => array(
248 'url' => site_url('/?mc_cart_update=2&lang1='.$locale),
249 'method' => 'POST'
250 ),
251 'notificationUrl' => array(
252 'url' => site_url('/?mc_cart_update=3&lang1='.$locale),
253 'method' => 'POST'
254 ),
255 )
256 );
257 header('Content-type: application/json');
258 echo json_encode($response);
259 exit;
260 }
261 if (intval(get_query_var('mc_calculate_shipment')) === 1) {
262 $cart_info = json_decode(file_get_contents('php://input'));
263 header('Content-type: application/json');
264 echo json_encode(array('amount' => 2.99));
265 }
266 if (intval(get_query_var('mc_cart_update')) > 0) {
267 $return_url = mk_check_payment();
268 if( isset($_GET["lang1"])) {
269 $return_url .= "&lang1=".$_GET["lang1"];
270 do_action('wpml_switch_language', $_GET["lang1"]);
271 }
272 if (intval(get_query_var('mc_cart_update')) === 3) {
273 echo json_encode(array('redirect' => $return_url));
274 } else {
275 wp_redirect($return_url);
276 }
277 exit;
278 }
279 }
280 function sc_cart_scripts() {
281 ?>
282 <script>
283 jQuery(document).on('updated_cart_totals', function(){
284 var rand = Math.round(Math.random() * 100000);
285 window.history.pushState({rand: rand}, "Rand "+rand, "./?r="+rand);
286 });
287 </script>
288 <?php
289 $mcsc = new woocommerce_makecommerce_sc();
290 $mcsc->before_cart();
291 }
292 add_filter('query_vars', 'sc_return_trigger');
293 add_action('template_redirect', 'sc_return_trigger_check');
294 add_action('woocommerce_before_cart', 'sc_cart_scripts');
295
296 function woocommerce_makecommerce_sc_init() {
297
298 load_plugin_textdomain('wc_makecommerce_domain', false, dirname(plugin_basename(__FILE__)) . '/languages/');
299
300 class woocommerce_makecommerce_sc extends WC_Payment_Gateway {
301 function __construct() {
302 $this->id = 'makecommerce_sc';
303 $this->method_title = __('SimpleCheckout (MC)', 'wc_makecommerce_domain');
304 $this->init();
305 }
306 function init() {
307 $this->init_form_fields();
308 $this->init_settings();
309 $this->enabled = $this->settings['active'];
310 add_action('woocommerce_before_checkout_form', array(&$this, 'take_over_checkout'), 10, 1);
311 add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
312 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options'));
313 }
314 function before_cart() {
315 if (!$this->is_available()) { return; }
316 if (!empty($this->settings['hide_shipping_methods']) && $this->settings['hide_shipping_methods'] === 'yes') {
317 echo '<style>.shipping,.order-total{display:none;}</style>';
318 echo '<style>.tax-rate{display:none;}</style>';
319 }
320 }
321 function install_tables() {
322 global $wpdb;
323 $charset_collate = $wpdb->get_charset_collate();
324 $table_name = $wpdb->prefix . "woocommerce_makecommerce_sc";
325 $sql = "CREATE TABLE `$table_name` (
326 `id` int(11) unsigned not null auto_increment,
327 `cart_id` varchar(64) not null default '',
328 `order_id` int(10) unsigned not null,
329 `created` int(10) unsigned not null,
330 `modified` int(10) unsigned not null,
331 `status` tinyint unsigned not null,
332 `content` mediumtext,
333 unique key id (`id`),
334 key cart_id (`cart_id`)
335 ) $charset_collate;";
336 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
337 dbDelta($sql);
338 }
339 function take_over_checkout($checkout) {
340 if (!$this->is_available()) {
341 return;
342 }
343 $this->install_tables();
344 global $woocommerce, $wpdb;
345 if (get_option('woocommerce_enable_guest_checkout') !== 'yes' && !is_user_logged_in()) {
346 wc_add_notice(__('You have to log in to continue to checkout', 'wc_makecommerce_domain'), 'error');
347 $redir_url = $woocommerce->cart->get_cart_url();
348 wp_redirect($redir_url);
349 exit;
350 }
351 $data = array(
352 'order' => array(),
353 'coupons' => $woocommerce->cart->get_applied_coupons(),
354 'discount' => $woocommerce->cart->get_cart_discount_total(),
355 'discount_tax' => $woocommerce->cart->get_cart_discount_tax_total()
356 );
357 $free_shipping = false;
358 foreach ($woocommerce->cart->get_applied_coupons() as $coupon) {
359 $coupon = new WC_Coupon($coupon);
360 if ((method_exists($coupon, 'get_free_shipping') && $coupon->get_free_shipping()) || $coupon->free_shipping) { $free_shipping = true; }
361 }
362 $qty = 0; $amount = 0;
363 $cart = $woocommerce->cart->get_cart();
364 foreach ($cart as $cart_item) {
365 $data['order'][] = array('id' => $cart_item['product_id'], 'qty' => $cart_item['quantity'], 'var' => $cart_item['variation_id']);
366 $qty += $cart_item['quantity'];
367 $amount += $cart_item['line_total'] + $cart_item['line_tax'];
368 }
369 if (count($data) > 0) {
370 $wpdb->insert($wpdb->prefix.'woocommerce_makecommerce_sc', array(
371 'created' => time(),
372 'modified' => time(),
373 'status' => 0,
374 'content' => json_encode($data)
375 ));
376 $locale = get_locale();
377 if ($locale) { $locale = explode('_', $locale); $locale = !empty($locale[1]) ? strtolower($locale[1]) : strtolower($locale[0]); }
378 $locale = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $locale;
379 if (empty($locale)) { $locale = 'et'; }
380
381 //polylang uses different locale names, while wpml uses lv, lt, en. Polylang uses lv_LV, lt_LT and en_GB
382 //this method should be improved and made generic everywhere
383 if (function_exists('pll_languages_list')) {
384 $locale = get_locale();
385 }
386
387 //locale has to be 2 chars:
388 $locale = substr($locale, 0, 2);
389
390 $tmp_order_id = $wpdb->insert_id;
391 $cart_to_order_url = site_url('/?mc_cart_to_order=1&lang1='.$locale);
392 $calculate_shipment_url = site_url('/?mc_calculate_shipment=1&lang1='.$locale);
393
394 //set correct tos url.
395 if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['shop_tos_url_'.$locale])) {
396 $tos_url = $this->settings['shop_tos_url_'.$locale];
397 } else {
398 if (!empty($this->settings['shop_tos_url'])) {
399 $tos_url = $this->settings['shop_tos_url'];
400 } else {
401 $tos_url = site_url();
402 }
403 }
404
405 $data = array(
406 'cartRef' => 'PreOrder '.$tmp_order_id,
407 'pluginUrls' => array(
408 'cartToOrder' => $cart_to_order_url,
409 'calculateShipment' => $calculate_shipment_url,
410 'tos' => $tos_url
411 ),
412 'amount' => sprintf("%.2f", round(max($amount, 0.01), 2)),
413 'currency' => 'EUR',
414 'sourceCountry' => WC()->countries->get_base_country(), // 'EE'
415 'locale' => $locale,
416 'shipmentMethods' => array()
417 );
418 $package = $woocommerce->cart->get_shipping_packages();
419 if (!empty($package)) { $package = $package[0]; }
420 $zones = array();
421
422 $zone = new WC_Shipping_Zone(0);
423 $zones[ $zone->get_id() ] = $zone->get_data();
424 $zones[ $zone->get_id() ]['formatted_zone_location'] = $zone->get_formatted_location();
425 $zones[ $zone->get_id() ]['shipping_methods'] = $zone->get_shipping_methods();
426 $zones = array_merge( $zones, WC_Shipping_Zones::get_zones() );
427 $continents = WC()->countries->get_continents();
428 $method_country_x = array();
429 $supported_methods = array('parcelmachine_omniva' => 'APT', 'parcelmachine_smartpost' => 'APT', 'parcelmachine_dpd' => 'APT', 'courier_omniva' => 'COU', 'courier_smartpost' => 'COU', 'local_pickup' => 'OTH', 'flat_rate' => 'COU');
430 foreach ($zones as $zone) {
431 foreach ($zone['shipping_methods'] as $method_key => $method) {
432 if ($method->enabled !== 'yes') { continue; }
433 $carrier = array('countries' => array());
434 if (!empty($supported_methods[$method->id])) {
435 foreach ($woocommerce->cart->get_shipping_packages() as $package) {
436 if (!$method->is_available($package)) { continue(2); }
437 }
438 $method_type = $supported_methods[$method->id];
439 if (empty($method_country_x[$method_type])) { $method_country_x[$method_type] = array(); }
440 if (!empty($method->carrier)) { $carrier['carrier'] = mb_strtoupper($method->carrier); }
441 if (empty($zone['zone_locations'])) {
442 $carrier['countries'] = array_keys(WC()->countries->get_allowed_countries());
443 } else {
444 foreach ($zone['zone_locations'] as $location) {
445 if ($location->type === 'continent' && !empty($continents[$location->code])) {
446 $countries = array_diff($continents[$location->code]['countries'], $method_country_x[$method_type]);
447 $carrier['countries'] = array_merge($carrier['countries'], $countries);
448 } else if ($location->type === 'state') {
449 list($country, $state) = explode(':', $location->code);
450 $carrier['countries'][] = $country;
451 } else if ($location->type === 'country') {
452 $carrier['countries'][] = $location->code;
453 }
454 }
455 }
456 $method_country_x[$method_type] = array_merge($method_country_x[$method_type], $carrier['countries']);
457 $prices = $method->get_rates_for_package($package);
458 $price = $free_shipping ? 0.00 : get_rate_with_taxes($method->id.':'.$method_key, $prices);
459 $carrier['type'] = strtoupper($method_type);
460 $carrier['name'] = $method->title;
461 $carrier['methodId'] = $method->id . ':' . $method_key;
462 $carrier['amount'] = sprintf("%.2f", round($price, 2));
463 $data['shipmentMethods'][] = $carrier;
464 }
465 }
466 }
467 $MK = mk_get_api();
468 $cart = $MK->createCart($data);
469 $wpdb->update($wpdb->prefix.'woocommerce_makecommerce_sc', array('cart_id' => $cart->id), array('id' => $tmp_order_id));
470
471 //add wp meta of the data provided to SCO. This way we can later check if the data values and so on were actually provided by us or the data has been manipulated by a mitm
472 $wpdb->insert($wpdb->prefix.'woocommerce_makecommerce_sc', array(
473 'cart_id' => $cart->id."_provided_sco_data",
474 'created' => time(),
475 'modified' => time(),
476 'status' => 0,
477 'content' => json_encode($data)
478 ));
479
480 wp_redirect($cart->scoUrl);
481 exit;
482 }
483 die('no content');
484 }
485 function init_form_fields() {
486 $this->form_fields = array();
487 $this->form_fields['logo'] = array('type' => 'title', 'description' => __get_logo_html());
488 $this->form_fields['scointro'] = array(
489 'type' => 'title',
490 'description' => __('SimpleCheckout replaces Woocommerce built-in check-out dialog with Makecommerce hosted dialog. It is more convenient and faster for your customers', 'wc_makecommerce_domain').'<br>'.__('See more about SimpleCheckout on: <a target=_blank href="https://makecommerce.net/simplecheckout/">makecommerce.net/simplecheckout</a>', 'wc_makecommerce_domain'),
491 );
492 $this->form_fields['active'] = array(
493 'title' => __('Enable/Disable', 'wc_makecommerce_domain'),
494 'type' => 'checkbox',
495 'label' => __('Enable SimpleCheckout', 'wc_makecommerce_domain'),
496 'default' => 'yes'
497 );
498
499 $languages = array();
500 if ( function_exists('icl_object_id') && !function_exists('pll_languages_list')) {
501 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
502 } else if (function_exists('pll_languages_list')) {
503 $pl_locales = pll_languages_list(array('fields'=>'locale'));
504 foreach ($pl_locales as $key => $locale_pl ) {
505 $language = array('id' => $key, 'code' => $locale_pl) ;
506 $languages[$locale_pl] = $language;
507 }
508 }
509
510 if (empty($languages)) {
511 $this->form_fields['shop_tos_url'] = array(
512 'title' => __('Shop ToS url', 'wc_makecommerce_domain'),
513 'description' => __('paste here url of your shop "Terms and Conditions" page', 'wc_makecommerce_domain'),
514 'type' => 'text',
515 );
516 } else {
517 foreach ($languages as $language_code=>$language) {
518 $shortLanguageCode = substr($language_code, 0, 2);
519 $this->form_fields['shop_tos_url_'.$shortLanguageCode] = array(
520 'title' => __('Shop ToS url', 'wc_makecommerce_domain').sprintf(' (%s)', $shortLanguageCode),
521 'description' => __('paste here url of your shop "Terms and Conditions" page', 'wc_makecommerce_domain'),
522 'type' => 'text',
523 );
524 }
525 }
526
527 $this->form_fields['hide_shipping_methods'] = array(
528 'title' => __('Hide shipping methods block', 'wc_makecommerce_domain'),
529 'type' => 'checkbox',
530 'label' => __('Hide shipping methods block on cart page. This will make it look more clean and simple', 'wc_makecommerce_domain'),
531 'default' => 'no'
532 );
533 }
534 public function is_available() {
535 if ($this->settings['active'] == "yes" || empty($this->settings['active'])) {
536 return true;
537 }
538 return false;
539 }
540
541 }
542
543 }
544
545 function get_rate_without_taxes($method, $rate) {
546 if (empty($rate[$method])) { return 0; }
547 $rate = $rate[$method];
548 $price = $rate->cost;
549 return $price;
550 }
551
552 function get_rate_with_taxes($method, $rate) {
553 if (empty($rate[$method])) { return 0; }
554 $rate = $rate[$method];
555 $price = $rate->cost;
556 if (empty($rate->taxes)) { return $price; }
557 foreach ($rate->taxes as $tax) {
558 $price += $tax;
559 }
560 return $price;
561 }
562
563 function woocommerce_payment_makecommerce_sc_add($methods) {
564 $methods[] = 'woocommerce_makecommerce_sc';
565 return $methods;
566 }
567 add_action('plugins_loaded', 'woocommerce_makecommerce_sc_init');
568 add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_sc_add');
569
570
571