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 / makecommerce-simplecheckout.php

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

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