| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: MakeCommerce for WooCommerce |
| 4 | 4 | Description: Adds MakeCommerce payment gateway and Itella/Omniva parcel machine shipping methods to Woocommerce checkout |
| 5 | - Version: 2.0.0 | |
| 5 | + Version: 1.1.7 | |
| 6 | 6 | Author: Maksekeskus AS |
| 7 | 7 | Author URI: https://MakeCommerce.net/ |
| 8 | 8 | Text Domain: wc_makecommerce_domain |
| 9 | 9 | */ |
| @@ -13,11 +13,8 @@ | ||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { |
| 16 | 16 | |
| 17 | - | |
| 18 | - define('WC_MC_VERSION', 2.0); | |
| 19 | - | |
| 20 | 17 | global $mkDbTable; |
| 21 | 18 | $mkDbTable = 'mc_banklinks'; |
| 22 | 19 | |
| 23 | 20 | function mc_install() { |
| @@ -42,29 +39,16 @@ | ||
| 42 | 39 | } |
| 43 | 40 | |
| 44 | 41 | register_activation_hook( __FILE__, 'mc_install' ); |
| 45 | 42 | |
| 46 | - // On uninstall remove scheduled hook | |
| 47 | - function mc_uninstall() { | |
| 48 | - if (wp_next_scheduled ( 'mc_banklinks_update_cron' )) { | |
| 49 | - wp_clear_scheduled_hook('mc_banklinks_update_cron'); | |
| 50 | - } | |
| 51 | - } | |
| 52 | - | |
| 53 | - register_deactivation_hook(__FILE__, 'mc_uninstall'); | |
| 54 | - | |
| 55 | - // WP schedule callable action | |
| 56 | - add_action('mc_banklinks_update_cron', 'update_mc_banklinks'); | |
| 57 | - | |
| 58 | 43 | if (!class_exists('wc_makecommerce_domain')) { |
| 59 | 44 | require_once('includes/Api.php'); |
| 60 | 45 | } |
| 61 | - | |
| 62 | 46 | |
| 63 | 47 | function woocommerce_payment_makecommerce_init() { |
| 64 | - | |
| 65 | 48 | load_plugin_textdomain('wc_makecommerce_domain', false, dirname(plugin_basename(__FILE__)) . '/'); |
| 66 | 49 | |
| 50 | + | |
| 67 | 51 | class woocommerce_makecommerce extends WC_Payment_Gateway { |
| 68 | 52 | |
| 69 | 53 | const MC_CANCELLED = 'CANCELLED'; |
| 70 | 54 | const MC_COMPLETED = 'COMPLETED'; |
| @@ -87,9 +71,9 @@ | ||
| 87 | 71 | const module_homepage_url = 'https://maksekeskus.ee/en/integration-modules/makecommerce-woocommerce-payment-plugin/'; |
| 88 | 72 | const testenv_homepage_url = 'http://maksekeskus.ee/en/for-developers/test-environment/'; |
| 89 | 73 | |
| 90 | 74 | public $id = 'makecommerce'; |
| 91 | - public $version = '2.0.0'; | |
| 75 | + public $version = '1.1.7'; | |
| 92 | 76 | |
| 93 | 77 | public $return_url; |
| 94 | 78 | public $return_url_cancel; |
| 95 | 79 | |
| @@ -164,30 +148,15 @@ | ||
| 164 | 148 | |
| 165 | 149 | wp_enqueue_script('jquery'); |
| 166 | 150 | wp_enqueue_style('makecommerce', plugins_url('/css/makecommerce.css', __FILE__), array(), $this->version); |
| 167 | 151 | } |
| 168 | - if (is_admin()) { | |
| 152 | + | |
| 153 | + if(is_admin()) { | |
| 169 | 154 | add_action( 'wp_ajax_mc_banklinks_reload', array(&$this, 'mc_banklinks_reload') ); |
| 170 | - require_once(ABSPATH.'wp-admin/includes/plugin.php'); | |
| 171 | - $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php'); | |
| 172 | - if ((double)$wc_version['Version'] < 2.6) { | |
| 173 | - function sample_admin_notice__error() { | |
| 174 | - $class = 'notice notice-error'; | |
| 175 | - $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php'); | |
| 176 | - $message = sprintf(__( 'Makecommerce plugin needs at least <strong>WooCommerce 2.6</strong> to function correctly. Please update yours (currently %s)', 'wc_makecommerce_domain' ), $wc_version['Version']); | |
| 177 | - printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); | |
| 178 | - } | |
| 179 | - add_action( 'admin_notices', 'sample_admin_notice__error' ); | |
| 180 | - } | |
| 181 | 155 | } |
| 182 | - | |
| 183 | 156 | } |
| 184 | - | |
| 185 | - public function get_title() { | |
| 186 | - return $this->title; | |
| 187 | - } | |
| 188 | 157 | |
| 189 | - public function makecommerce_api_info_missing() { | |
| 158 | + function makecommerce_api_info_missing() { | |
| 190 | 159 | ?> |
| 191 | 160 | <div class="notice notice-error is-dismissible"> |
| 192 | 161 | <p> |
| 193 | 162 | <?php echo __('You have not entered the Shop ID and keys for the MakeCommerce payment module. The module will not work without them.', 'wc_makecommerce_domain'); ?> |
| @@ -196,9 +165,9 @@ | ||
| 196 | 165 | </div> |
| 197 | 166 | <?php |
| 198 | 167 | } |
| 199 | 168 | |
| 200 | - public function makecommerce_banklinks_list_empty() { | |
| 169 | + function makecommerce_banklinks_list_empty() { | |
| 201 | 170 | ?> |
| 202 | 171 | <div class="notice notice-error is-dismissible"> |
| 203 | 172 | <p> |
| 204 | 173 | <?php echo __('The payment methods list for MakeCommerce payment module is empty.', 'wc_makecommerce_domain'); ?> |
| @@ -207,9 +176,9 @@ | ||
| 207 | 176 | </div> |
| 208 | 177 | <?php |
| 209 | 178 | } |
| 210 | 179 | |
| 211 | - public function makecommerce_banklinks_list_type_notice() { | |
| 180 | + function makecommerce_banklinks_list_type_notice() { | |
| 212 | 181 | ?> |
| 213 | 182 | <div class="notice notice-error is-dismissible"> |
| 214 | 183 | <p> |
| 215 | 184 | <?php echo __('You have changed the environment for MakeCommerce payment module. The payment methods list has been loaded for a different environment.', 'wc_makecommerce_domain'); ?> |
| @@ -221,21 +190,11 @@ | ||
| 221 | 190 | |
| 222 | 191 | /** |
| 223 | 192 | * Initialise Gateway Settings Form Fields |
| 224 | 193 | */ |
| 225 | - public function init_form_fields() { | |
| 194 | + function init_form_fields() { | |
| 226 | 195 | |
| 227 | - if ( function_exists('icl_object_id') && ! defined( 'POLYLANG_VERSION' ) ) { | |
| 228 | - $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 229 | - } | |
| 230 | - else if ( defined( 'POLYLANG_VERSION' ) ) { | |
| 231 | - $pl_locales = pll_languages_list( array('fields'=>'locale') ); | |
| 232 | - foreach ($pl_locales as $key => $locale_pl ) { | |
| 233 | - $language = array( 'id' => $key, | |
| 234 | - 'code' => $locale_pl) ; | |
| 235 | - $languages[$locale_pl] = $language; | |
| 236 | - } | |
| 237 | - } | |
| 196 | + $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 238 | 197 | |
| 239 | 198 | $this->form_fields = array(); |
| 240 | 199 | $this->form_fields['header'] = array( |
| 241 | 200 | 'type' => 'mc_header', |
| @@ -322,14 +281,8 @@ | ||
| 322 | 281 | 'type' => 'mc_hidden', |
| 323 | 282 | 'default' => 'no', |
| 324 | 283 | 'class' => 'ui-identifier', |
| 325 | 284 | ); |
| 326 | - $this->form_fields['ui_widget_countries_hidden'] = array( | |
| 327 | - 'title' => __('Hide country selector', 'wc_makecommerce_domain'), | |
| 328 | - 'label' => __('Do not display country selector (flags) at payment methods', 'wc_makecommerce_domain'), | |
| 329 | - 'type' => 'checkbox', | |
| 330 | - 'default' => 'no', | |
| 331 | - ); | |
| 332 | 285 | $this->form_fields['ui_widget_countryselector'] = array( |
| 333 | 286 | 'title' => __('Country selector style', 'wc_makecommerce_domain'), |
| 334 | 287 | 'type' => 'mc_hidden', |
| 335 | 288 | 'default' => 'flag', |
| @@ -569,12 +522,16 @@ | ||
| 569 | 522 | if ($force || (defined('DOING_AJAX') && DOING_AJAX)) { |
| 570 | 523 | |
| 571 | 524 | global $wpdb; |
| 572 | 525 | global $mkDbTable; |
| 526 | + global $wp_version; | |
| 573 | 527 | |
| 528 | + $tableName = $wpdb->prefix . $mkDbTable; | |
| 529 | + $wpdb->query('TRUNCATE TABLE '.$tableName); | |
| 530 | + | |
| 574 | 531 | $request_params = array( |
| 575 | 532 | 'environment' => json_encode(array( |
| 576 | - 'platform' => 'woocommerce '.$this->_getWooCommerce()->version, | |
| 533 | + 'platform' => 'wordpress '.$wp_version, | |
| 577 | 534 | 'module' => $this->id.' '.$this->version, |
| 578 | 535 | )), |
| 579 | 536 | ); |
| 580 | 537 | |
| @@ -589,11 +546,8 @@ | ||
| 589 | 546 | error_log(print_r($e, 1)); |
| 590 | 547 | return false; |
| 591 | 548 | } |
| 592 | 549 | |
| 593 | - $tableName = $wpdb->prefix . $mkDbTable; | |
| 594 | - $wpdb->query('TRUNCATE TABLE '.$tableName); | |
| 595 | - | |
| 596 | 550 | if(isset($methods->banklinks)) { |
| 597 | 551 | foreach($methods->banklinks as $method) { |
| 598 | 552 | $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url)); |
| 599 | 553 | } |
| @@ -635,19 +589,19 @@ | ||
| 635 | 589 | global $woocommerce; |
| 636 | 590 | return $woocommerce; |
| 637 | 591 | } |
| 638 | 592 | |
| 639 | - public function is_valid_for_use() { | |
| 593 | + function is_valid_for_use() { | |
| 640 | 594 | return true; |
| 641 | 595 | } |
| 642 | 596 | |
| 643 | 597 | public function is_available() { |
| 644 | - if ($this->settings['active'] == "yes" && mk_is_api_set()) { | |
| 598 | + if ($this->settings['active'] == "yes") { | |
| 645 | 599 | return true; |
| 646 | 600 | } |
| 647 | 601 | } |
| 648 | 602 | |
| 649 | - public function payment_fields() { | |
| 603 | + function payment_fields() { | |
| 650 | 604 | |
| 651 | 605 | if($this->settings['ui_mode'] == 'inline') { |
| 652 | 606 | |
| 653 | 607 | ?> |
| @@ -693,9 +647,9 @@ | ||
| 693 | 647 | |
| 694 | 648 | if($this->_banklinks) { |
| 695 | 649 | $defaultCountry = $this->getDefaultCountry(); |
| 696 | 650 | ?> |
| 697 | - <?php if( ( empty($this->settings['ui_widget_groupcountries']) || $this->settings['ui_widget_groupcountries'] == 'no' ) && (!isset($this->settings['ui_widget_countries_hidden']) || $this->settings['ui_widget_countries_hidden'] == 'no') ) : ?> | |
| 651 | + <?php if(empty($this->settings['ui_widget_groupcountries']) || $this->settings['ui_widget_groupcountries'] == 'no') : ?> | |
| 698 | 652 | <div class="makecommerce_country_picker_countries"> |
| 699 | 653 | <?php foreach(array_keys($this->_banklinks_grouped) as $country): ?> |
| 700 | 654 | <input style="display: none;" type="radio" id="makecommerce_country_picker_<?php echo $country; ?>" name="makecommerce_country_picker" value="<?php echo $country; ?>" <?php if($defaultCountry == $country) echo 'checked="checked" '; ?>/><?php if($this->settings['ui_widget_countryselector'] == 'flag') { ?><label for="makecommerce_country_picker_<?php echo $country; ?>" class="makecommerce_country_picker_label" style="background-image: url(<?php echo plugins_url('/images/'.$country.'32.png', __FILE__); ?>);"></label><?php } ?> |
| 701 | 655 | <?php endforeach; ?> |
| @@ -708,15 +662,9 @@ | ||
| 708 | 662 | </select> |
| 709 | 663 | <?php endif; ?> |
| 710 | 664 | </div> |
| 711 | 665 | <?php endif; ?> |
| 712 | - <?php | |
| 713 | - $banklinks_grouped = $this->_banklinks_grouped; | |
| 714 | - if(count($banklinks_grouped) > 1) { | |
| 715 | - $banklinks_grouped['other'] = array(); | |
| 716 | - } | |
| 717 | - ?> | |
| 718 | - <?php foreach($banklinks_grouped as $country => $methods): ?> | |
| 666 | + <?php foreach($this->_banklinks_grouped as $country => $methods): ?> | |
| 719 | 667 | <li class="makecommerce-picker-country"> |
| 720 | 668 | <?php if($this->settings['ui_widget_groupcountries'] == 'yes') : ?> |
| 721 | 669 | <input type="radio" id="makecommerce_country_picker_<?php echo $country; ?>" name="makecommerce_country_picker" value="<?php echo $country; ?>" <?php if($defaultCountry == $country) echo 'checked="checked" '; ?>/><label for="makecommerce_country_picker_<?php echo $country; ?>"><img src="<?php echo plugins_url('/images/'.$country.'32.png', __FILE__); ?>" /></label> |
| 722 | 670 | <?php endif; ?> |
| @@ -732,10 +680,8 @@ | ||
| 732 | 680 | <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>"> |
| 733 | 681 | <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> |
| 734 | 682 | </div> |
| 735 | 683 | <?php endforeach; ?> |
| 736 | - <?php elseif($country == 'other') :?> | |
| 737 | - <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p> | |
| 738 | 684 | <?php endif; ?> |
| 739 | 685 | </div> |
| 740 | 686 | </li> |
| 741 | 687 | <?php endforeach; ?> |
| @@ -757,15 +703,15 @@ | ||
| 757 | 703 | </ul> |
| 758 | 704 | <div class="mc-clear-both"></div> |
| 759 | 705 | <script type="text/javascript"> |
| 760 | 706 | var makecommerceId = '<?php echo $this->id; ?>'; |
| 761 | - var selectedCountry = '<?php echo $defaultCountry; ?>'; | |
| 707 | + var selectedCountry = jQuery('input[name=makecommerce_country_picker]:checked').val(); | |
| 762 | 708 | |
| 763 | 709 | var logosize = '<?php echo $this->settings['ui_widget_logosize']; ?>'; |
| 764 | 710 | jQuery('div.makecommerce_country_picker_methods').addClass('logosize-'+logosize); |
| 765 | 711 | |
| 766 | 712 | <?php if(count($this->_banklinks_grouped) == 1): ?> |
| 767 | - jQuery('li.makecommerce-picker-country').show(); | |
| 713 | + jQuery('div.makecommerce_country_picker_methods').show(); | |
| 768 | 714 | jQuery('div.makecommerce_country_picker_countries').hide(); |
| 769 | 715 | jQuery('li.makecommerce-picker-country > input, li.makecommerce-picker-country > label').hide(); |
| 770 | 716 | <?php else: ?> |
| 771 | 717 | makecommercePick(); |
| @@ -785,10 +731,10 @@ | ||
| 785 | 731 | jQuery('select#'+makecommerceId).val(''); |
| 786 | 732 | jQuery('div.makecommerce-banklink-picker').removeClass('selected'); |
| 787 | 733 | jQuery('label.makecommerce_country_picker_label').removeClass('selected'); |
| 788 | 734 | |
| 789 | - jQuery('li.makecommerce-picker-country').hide(); | |
| 790 | - jQuery('div#makecommerce_country_picker_methods_' + selectedCountry).parent().show(); | |
| 735 | + jQuery('div.makecommerce_country_picker_methods').hide(); | |
| 736 | + jQuery('div#makecommerce_country_picker_methods_' + selectedCountry).show(); | |
| 791 | 737 | jQuery('label[for=makecommerce_country_picker_' + selectedCountry + ']').addClass('selected'); |
| 792 | 738 | } |
| 793 | 739 | <?php endif; ?> |
| 794 | 740 | |
| @@ -816,10 +762,8 @@ | ||
| 816 | 762 | if ($this->_getWooCommerce()->customer) { |
| 817 | 763 | $customerCountry = strtolower($this->_getWooCommerce()->customer->get_shipping_country()); |
| 818 | 764 | if(array_key_exists($customerCountry, $this->_banklinks_grouped)) { |
| 819 | 765 | return $customerCountry; |
| 820 | - } else { | |
| 821 | - return 'other'; | |
| 822 | 766 | } |
| 823 | 767 | } |
| 824 | 768 | |
| 825 | 769 | $localeToCountry = array( |
| @@ -902,9 +846,9 @@ | ||
| 902 | 846 | |
| 903 | 847 | return true; |
| 904 | 848 | } |
| 905 | 849 | |
| 906 | - public function process_payment($orderId) { | |
| 850 | + function process_payment($orderId) { | |
| 907 | 851 | |
| 908 | 852 | $order = new WC_Order($orderId); |
| 909 | 853 | |
| 910 | 854 | $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false; |
| @@ -1021,28 +965,14 @@ | ||
| 1021 | 965 | return false; |
| 1022 | 966 | } |
| 1023 | 967 | |
| 1024 | 968 | protected function _getOrderConfirmationUrl($order) { |
| 1025 | - | |
| 1026 | - global $sitepress; | |
| 1027 | - if(isset($sitepress)) { | |
| 1028 | - $baseUrl = $sitepress->language_url( ICL_LANGUAGE_CODE ); | |
| 1029 | - $lang = ICL_LANGUAGE_CODE; | |
| 1030 | - } else { | |
| 1031 | - $baseUrl = site_url(); | |
| 1032 | - $lang = strtolower(substr(get_locale(), 0, 2)); | |
| 1033 | - } | |
| 1034 | - $url = add_query_arg( array( | |
| 1035 | - 'makecommerce_card_pay' => '1', | |
| 1036 | - 'order_id' => $order->id, | |
| 1037 | - 'lang' => $lang, | |
| 1038 | - ), $baseUrl); | |
| 1039 | - | |
| 1040 | - // $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id.'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2)))); | |
| 969 | + //$url = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id')))); | |
| 970 | + $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id.'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2)))); | |
| 1041 | 971 | return $url; |
| 1042 | 972 | } |
| 1043 | 973 | |
| 1044 | - public function receipt_page($orderId) { | |
| 974 | + function receipt_page($orderId) { | |
| 1045 | 975 | echo '<p>' . __('Thank you for the order, please click on the button to start the payment.', 'wc_makecommerce_domain') . '</p>'; |
| 1046 | 976 | |
| 1047 | 977 | $order = new WC_Order($orderId); |
| 1048 | 978 | if(substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') { |
| @@ -1049,9 +979,9 @@ | ||
| 1049 | 979 | echo $this->generateCardForm($order); |
| 1050 | 980 | } |
| 1051 | 981 | } |
| 1052 | 982 | |
| 1053 | - public function generateCardForm($order) { | |
| 983 | + function generateCardForm($order) { | |
| 1054 | 984 | $scriptSrc = htmlspecialchars($this->_gateway_url_static.'checkout.js'); |
| 1055 | 985 | $transactionId = get_post_meta($order->id, '_makecommerce_cc_transaction_id', true); |
| 1056 | 986 | $idReference = $order->id; |
| 1057 | 987 | $jsParams = array( |
| @@ -1099,21 +1029,21 @@ | ||
| 1099 | 1029 | } |
| 1100 | 1030 | return implode(' ', $result); |
| 1101 | 1031 | } |
| 1102 | 1032 | |
| 1103 | - public function makecommerce_return_trigger($vars) { | |
| 1033 | + function makecommerce_return_trigger($vars) { | |
| 1104 | 1034 | $vars[] = 'makecommerce_return'; |
| 1105 | 1035 | $vars[] = 'makecommerce_card_pay'; |
| 1106 | 1036 | return $vars; |
| 1107 | 1037 | } |
| 1108 | 1038 | |
| 1109 | - public function makecommerce_return_trigger_check() { | |
| 1039 | + function makecommerce_return_trigger_check() { | |
| 1110 | 1040 | if(intval(get_query_var('makecommerce_return')) == 1) { |
| 1111 | 1041 | |
| 1112 | 1042 | $returnUrl = home_url(); |
| 1113 | 1043 | |
| 1114 | 1044 | $request = stripslashes_deep($_POST); |
| 1115 | - if($this->_api->verifyMac($request)) { | |
| 1045 | + if($this->_api->verifySignature($request)) { | |
| 1116 | 1046 | $data = $this->_api->extractRequestData($request); |
| 1117 | 1047 | $order = new WC_Order($data['reference']); |
| 1118 | 1048 | |
| 1119 | 1049 | switch($data['status']) { |
| @@ -1155,20 +1085,21 @@ | ||
| 1155 | 1085 | |
| 1156 | 1086 | } elseif(intval(get_query_var('makecommerce_return')) == 2) { |
| 1157 | 1087 | |
| 1158 | 1088 | $returnUrl = home_url(); |
| 1089 | + | |
| 1159 | 1090 | if(isset($_POST['paymentToken']) && isset($_POST['transaction'])) { |
| 1160 | 1091 | $token = $_POST['paymentToken']; |
| 1161 | 1092 | $transaction = $_POST['transaction']; |
| 1162 | 1093 | } |
| 1163 | 1094 | |
| 1164 | - if(isset($_POST['json']) && $this->_api->verifyMac(stripslashes_deep($_POST))) { | |
| 1095 | + if(isset($_POST['json'])) { | |
| 1165 | 1096 | $data = json_decode(stripslashes($_POST['json']), true); |
| 1166 | 1097 | $token = $data['token']['id']; |
| 1167 | 1098 | $transaction = $data['transaction']['id']; |
| 1168 | 1099 | } |
| 1169 | 1100 | |
| 1170 | - if(isset($token) && isset($transaction) && !empty($token) && !empty($transaction)) { | |
| 1101 | + if(!empty($token) && !empty($transaction)) { | |
| 1171 | 1102 | global $wpdb; |
| 1172 | 1103 | if($order = New WC_Order($wpdb->get_var('SELECT post_id from '.$wpdb->postmeta.' where meta_key = "_makecommerce_cc_transaction_id" AND meta_value = "'.$transaction.'"'))) { |
| 1173 | 1104 | $request_body = array( |
| 1174 | 1105 | 'token' => $token, |
| @@ -1255,9 +1186,9 @@ | ||
| 1255 | 1186 | |
| 1256 | 1187 | return true; |
| 1257 | 1188 | } |
| 1258 | 1189 | |
| 1259 | - public function admin_order_page($order) { | |
| 1190 | + function admin_order_page($order) { | |
| 1260 | 1191 | // |
| 1261 | 1192 | } |
| 1262 | 1193 | |
| 1263 | 1194 | public function process_refund($order_id, $amount = null, $comment = '') { |
| @@ -1303,45 +1234,11 @@ | ||
| 1303 | 1234 | |
| 1304 | 1235 | } |
| 1305 | 1236 | |
| 1306 | 1237 | New woocommerce_makecommerce(true); |
| 1307 | - | |
| 1308 | - // Woocommerce Multilingual overrides | |
| 1309 | - if ( in_array( 'woocommerce-multilingual/wpml-woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 1310 | - add_filter( 'get_post_metadata', 'mc_override_payment_method_string', 5, 4 ); | |
| 1311 | - } | |
| 1312 | - | |
| 1313 | - // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible | |
| 1314 | - // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site | |
| 1315 | - if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) { | |
| 1316 | - $date = new DateTime(); | |
| 1317 | - $date->setTime(23,59,59); | |
| 1318 | - $timestamp = intval($date->format('U')); | |
| 1319 | - $local = 3600 * intval(get_option('gmt_offset')); | |
| 1320 | - wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron'); | |
| 1321 | - } | |
| 1238 | + | |
| 1322 | 1239 | } |
| 1323 | 1240 | |
| 1324 | - function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){ | |
| 1325 | - if($meta_key == '_payment_method_title') { | |
| 1326 | - $payment_method = get_post_meta( $object_id, '_payment_method', true ); | |
| 1327 | - if( $payment_method == 'makecommerce' ){ | |
| 1328 | - $payment_gateways = WC()->payment_gateways->payment_gateways(); | |
| 1329 | - if( isset( $payment_gateways[ $payment_method ] ) ){ | |
| 1330 | - $title = $payment_gateways[ $payment_method ]->title; | |
| 1331 | - return $title; | |
| 1332 | - } | |
| 1333 | - } | |
| 1334 | - } | |
| 1335 | - return $check; | |
| 1336 | - } | |
| 1337 | - | |
| 1338 | - // Banklinks update wrapper for action | |
| 1339 | - function update_mc_banklinks() { | |
| 1340 | - $obj = new woocommerce_makecommerce(true); | |
| 1341 | - $obj->mc_banklinks_reload(true); | |
| 1342 | - } | |
| 1343 | - | |
| 1344 | 1241 | function woocommerce_payment_makecommerce_add($methods) { |
| 1345 | 1242 | $methods[] = 'woocommerce_makecommerce'; |
| 1346 | 1243 | return $methods; |
| 1347 | 1244 | } |
| @@ -1357,13 +1254,10 @@ | ||
| 1357 | 1254 | } |
| 1358 | 1255 | } |
| 1359 | 1256 | add_filter('woocommerce_checkout_update_order_review', 'clear_wc_shipping_rates_cache'); |
| 1360 | 1257 | |
| 1361 | - | |
| 1362 | - | |
| 1363 | - | |
| 1364 | 1258 | // Parcel machine specific stuff |
| 1365 | - function transport_add_method() { | |
| 1259 | + function parcelmachine_add_method() { | |
| 1366 | 1260 | |
| 1367 | 1261 | // Delete all the wc_ship transient scum, you aren’t wanted around here, move along. |
| 1368 | 1262 | // Same as being in shipping debug mode |
| 1369 | 1263 | global $wpdb; |
| @@ -1379,22 +1273,20 @@ | ||
| 1379 | 1273 | if (WC()->session) { |
| 1380 | 1274 | WC()->session->set('shipping_for_package', ''); |
| 1381 | 1275 | } |
| 1382 | 1276 | |
| 1383 | - | |
| 1384 | 1277 | if ( ! class_exists( 'WC_ParcelMachine_Shipping_Method' ) ) { |
| 1385 | 1278 | |
| 1386 | 1279 | class WC_ParcelMachine_Shipping_Method extends WC_Shipping_Method { |
| 1387 | 1280 | |
| 1281 | + | |
| 1388 | 1282 | function __construct($instance_id = 0) { |
| 1389 | 1283 | if (!$this->ext) { |
| 1390 | 1284 | throw new Exception('Do not call this class directly!'); |
| 1391 | 1285 | } |
| 1392 | 1286 | $this->id = 'parcelmachine_' . mb_strtolower($this->ext); |
| 1393 | - $this->instance_id = absint($instance_id); | |
| 1394 | - $this->method_title = $this->name_ext . __(' Parcel Machine (MC)', 'wc_makecommerce_domain'); | |
| 1395 | - // $this->method_description = sprintf(__('Parcel machine transport method for %s', 'wc_makecommerce_domain'), $this->ext); | |
| 1396 | - $this->supports = array('shipping-zones', 'instance-settings', 'instance-settings-modal', 'settings'); | |
| 1287 | + $this->instance_id = $instance_id; | |
| 1288 | + $this->method_title = $this->name_ext . __(' Parcel Machine by MC', 'wc_makecommerce_domain'); | |
| 1397 | 1289 | $this->init(); |
| 1398 | 1290 | } |
| 1399 | 1291 | |
| 1400 | 1292 | function init() { |
| @@ -1408,9 +1300,9 @@ | ||
| 1408 | 1300 | } |
| 1409 | 1301 | $this->availability = 'specific'; |
| 1410 | 1302 | $this->countries = $this->settings['countries']; |
| 1411 | 1303 | $this->prioritization = $this->settings['prioritization']; |
| 1412 | - $this->free_shipping_min_amount = !empty($this->settings['free_shipping_min_amount']) ? $this->settings['free_shipping_min_amount'] : 0; | |
| 1304 | + $this->free_shipping_min_amount = $this->settings['free_shipping_min_amount']; | |
| 1413 | 1305 | $this->maximum_weight = (double)$this->settings['maximum_weight']; |
| 1414 | 1306 | $this->short_office_names = $this->settings['short_office_names']; |
| 1415 | 1307 | $this->order_country = 'unknown'; |
| 1416 | 1308 | add_action('woocommerce_update_options_shipping_' . $this->id, array(&$this, 'process_admin_options')); |
| @@ -1419,38 +1311,10 @@ | ||
| 1419 | 1311 | add_action('woocommerce_checkout_process', array(&$this, 'check_parcelmachine_checkout_fields')); |
| 1420 | 1312 | add_action('woocommerce_after_checkout_validation', array(&$this, 'check_parcelmachine_checkout_fields')); |
| 1421 | 1313 | add_action('woocommerce_checkout_update_order_meta', array(&$this, 'add_parcelmachine_order_meta')); |
| 1422 | 1314 | add_filter('woocommerce_order_shipping_to_display_shipped_via', array(&$this, 'add_admin_parcelmachine_via_field')); |
| 1423 | - | |
| 1424 | - // Woocommerce Multilingual overrides | |
| 1425 | - if ( in_array( 'woocommerce-multilingual/wpml-woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 1426 | - add_filter('woocommerce_package_rates', array($this, 'override_label_translation'), 50); | |
| 1427 | - add_filter('woocommerce_order_get_items', array($this, 'override_shipping_title_translation'), 50, 2); | |
| 1428 | - } | |
| 1429 | 1315 | } |
| 1430 | 1316 | |
| 1431 | - public function override_label_translation($rates) { | |
| 1432 | - $id_instance = $this->id . ':' . $this->instance_id; | |
| 1433 | - if(array_key_exists($id_instance, $rates)) { | |
| 1434 | - $rates[$id_instance]->label = $this->title; | |
| 1435 | - } | |
| 1436 | - return $rates; | |
| 1437 | - } | |
| 1438 | - | |
| 1439 | - public function override_shipping_title_translation($items, $order) { | |
| 1440 | - foreach ($items as $key => $item) { | |
| 1441 | - if($item['type'] == 'shipping') { | |
| 1442 | - foreach ($item['item_meta_array'] as $meta) { | |
| 1443 | - $tmp = explode(':', $meta->value); | |
| 1444 | - if($meta->key == 'method_id' && $tmp[0] == $this->id) { | |
| 1445 | - $items[$key]['name'] = $this->title; | |
| 1446 | - } | |
| 1447 | - } | |
| 1448 | - } | |
| 1449 | - } | |
| 1450 | - return $items; | |
| 1451 | - } | |
| 1452 | - | |
| 1453 | 1317 | public function generate_shipping_ui_javascript_html( $key, $data ) { ?> |
| 1454 | 1318 | <script type="text/javascript"> |
| 1455 | 1319 | jQuery(document).ready(function($) { |
| 1456 | 1320 | var country_select = $('#woocommerce_parcelmachine_<?php echo strtolower($this->ext); ?>_countries'); |
| @@ -1481,11 +1345,11 @@ | ||
| 1481 | 1345 | </script> |
| 1482 | 1346 | <?php } |
| 1483 | 1347 | |
| 1484 | 1348 | function calculate_shipping($package = array()) { |
| 1485 | - $price = isset($this->instance_settings['price']) ? $this->instance_settings['price'] : (isset($this->settings['price_'.$package['destination']['country']]) ? $this->settings['price_'.$package['destination']['country']] : 0); | |
| 1349 | + $price = $this->settings['price_'.strtolower($package['destination']['country'])]; | |
| 1486 | 1350 | |
| 1487 | - $free_shipping_min_amount = $this->instance_settings['free_shipping_min_amount']; | |
| 1351 | + $free_shipping_min_amount = $this->settings['free_shipping_min_amount_'.strtolower($package['destination']['country'])]; | |
| 1488 | 1352 | |
| 1489 | 1353 | if ($free_shipping_min_amount && $package['contents_cost'] >= $free_shipping_min_amount) { |
| 1490 | 1354 | $price = 0; |
| 1491 | 1355 | } |
| @@ -1497,12 +1361,11 @@ | ||
| 1497 | 1361 | if($free_shipping) { |
| 1498 | 1362 | $price = 0; |
| 1499 | 1363 | } |
| 1500 | 1364 | $rate = array( |
| 1501 | - 'id' => $this->get_rate_id(), | |
| 1365 | + 'id' => $this->id, | |
| 1502 | 1366 | 'label' => $this->title, |
| 1503 | 1367 | 'cost' => $price, |
| 1504 | - 'package' => $package, | |
| 1505 | 1368 | 'calc_tax' => 'per_order', |
| 1506 | 1369 | ); |
| 1507 | 1370 | $this->add_rate( $rate ); |
| 1508 | 1371 | } |
| @@ -1513,9 +1376,8 @@ | ||
| 1513 | 1376 | $weight += $line['data']->get_weight(); |
| 1514 | 1377 | } |
| 1515 | 1378 | return $weight; |
| 1516 | 1379 | } |
| 1517 | - | |
| 1518 | 1380 | function fits_parcel_machine($package) { |
| 1519 | 1381 | foreach ($package['contents'] as $line) { |
| 1520 | 1382 | if (get_post_meta($line['product_id'], '_no_parcel_machine', true) === 'yes') { |
| 1521 | 1383 | return false; |
| @@ -1523,8 +1385,9 @@ | ||
| 1523 | 1385 | } |
| 1524 | 1386 | return true; |
| 1525 | 1387 | } |
| 1526 | 1388 | |
| 1389 | + | |
| 1527 | 1390 | function is_available($package) { |
| 1528 | 1391 | if (!$this->fits_parcel_machine($package)) { |
| 1529 | 1392 | return false; |
| 1530 | 1393 | } |
| @@ -1532,9 +1395,9 @@ | ||
| 1532 | 1395 | if ($package_weight >= $this->maximum_weight) { |
| 1533 | 1396 | return false; |
| 1534 | 1397 | } |
| 1535 | 1398 | $is_available = $this->enable === 'yes'; |
| 1536 | - if (!$is_available || !mk_is_api_set()) { | |
| 1399 | + if (!$is_available) { | |
| 1537 | 1400 | return false; |
| 1538 | 1401 | } |
| 1539 | 1402 | if (is_array($this->countries) && !in_array($package['destination']['country'], $this->countries)) { |
| 1540 | 1403 | $is_available = false; |
| @@ -1547,11 +1410,11 @@ | ||
| 1547 | 1410 | $machines = mk_get_machines($this->ext, $this->order_country); |
| 1548 | 1411 | if ($this->prioritization === 'yes') { |
| 1549 | 1412 | usort($machines, function($a, $b) { |
| 1550 | 1413 | $sortorder = array( |
| 1551 | - 'tallinn', 'tartu linn','tartu', 'narva', 'pärnu linn','pärnu', 'viljandi', 'kohtla-järve', 'rakvere', 'maardu', 'sillamäe', 'kuressaare', | |
| 1414 | + 'tallinn', 'tartu', 'narva', 'pärnu', 'viljandi', 'kohtla-järve', 'rakvere', 'maardu', 'sillamäe', 'kuressaare', | |
| 1552 | 1415 | 'helsinki', 'espoo', 'tampere', 'vantaa', 'oulu', 'turku', 'jüväskülä', 'lahti', 'kuopio', 'kouvola', |
| 1553 | - 'rīga','riga', 'daugavpils', 'liepāja','liepaja', 'jelgava', 'jūrmala','jurmala', 'ventspils', 'rezekne', 'valmiera', 'jekabpils', | |
| 1416 | + 'riga', 'daugavpils', 'liepaja', 'jelgava', 'jurmala', 'ventspils', 'rezekne', 'valmiera', 'jekabpils', | |
| 1554 | 1417 | 'vilnius', 'kaunas', 'klaipeda', 'siauliai', 'panevezys', 'alytus', 'mariampole', 'mazeikiai', 'jonava', 'utena' |
| 1555 | 1418 | ); |
| 1556 | 1419 | $acity = mb_strtolower($a['city']); |
| 1557 | 1420 | $bcity = mb_strtolower($b['city']); |
| @@ -1605,51 +1468,32 @@ | ||
| 1605 | 1468 | } |
| 1606 | 1469 | |
| 1607 | 1470 | function check_parcelmachine_checkout_fields() { |
| 1608 | 1471 | $shipping_method = !empty($_POST['shipping_method']) ? $_POST['shipping_method'] : false; |
| 1609 | - if (!empty($shipping_method[0])) { $shipping_method_ext = explode(':', $shipping_method[0]); } | |
| 1610 | - if ($shipping_method_ext[0] === $this->id && empty($_POST[$shipping_method_ext[0]])) { | |
| 1472 | + if (!empty($shipping_method[0])) { $shipping_method = $shipping_method[0]; } | |
| 1473 | + if ($shipping_method === $this->id && empty($_POST[$shipping_method])) { | |
| 1611 | 1474 | wc_add_notice(__('<strong>Parcel machine</strong> is a required field.'), 'error'); |
| 1612 | 1475 | } |
| 1613 | 1476 | } |
| 1614 | - | |
| 1615 | 1477 | function add_parcelmachine_order_meta($order_id) { |
| 1616 | 1478 | $shipping_method = !empty($_POST['shipping_method']) ? $_POST['shipping_method'] : false; |
| 1617 | - if (!empty($shipping_method[0])) { $shipping_method_ext = explode(':', $shipping_method[0]); } | |
| 1618 | - if ($shipping_method_ext[0] === $this->id && !empty($_POST[$this->id])) { | |
| 1479 | + if (!empty($shipping_method[0])) { $shipping_method = $shipping_method[0]; } | |
| 1480 | + if ($shipping_method === $this->id && !empty($_POST[$this->id])) { | |
| 1619 | 1481 | update_post_meta($order_id, '_parcel_machine', sanitize_text_field($_POST[$this->id])); |
| 1620 | 1482 | } |
| 1621 | 1483 | } |
| 1622 | - | |
| 1623 | 1484 | function add_admin_parcelmachine_via_field($order) { |
| 1624 | 1485 | return ' <small>(via '.$this->name_ext.')</small>'; |
| 1625 | 1486 | } |
| 1626 | 1487 | } |
| 1627 | - | |
| 1628 | 1488 | class WC_ParcelMachine_Shipping_Method_Omniva extends WC_ParcelMachine_Shipping_Method { |
| 1629 | 1489 | function __construct($instance_id = 0) { |
| 1630 | 1490 | $this->ext = 'Omniva'; |
| 1631 | 1491 | $this->name_ext = 'Omniva'; |
| 1632 | - $this->carrier = 'omniva'; | |
| 1633 | - $this->type = 'apt'; | |
| 1634 | - parent::__construct($instance_id); | |
| 1492 | + parent::__construct(); | |
| 1635 | 1493 | } |
| 1636 | 1494 | function init_form_fields() { |
| 1637 | 1495 | |
| 1638 | - $this->instance_form_fields = array(); | |
| 1639 | - $this->instance_form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 1640 | - $this->instance_form_fields['price'] = array( | |
| 1641 | - 'title' => __('Shipping price', 'wc_makecommerce_domain'), | |
| 1642 | - 'type' => 'text', | |
| 1643 | - 'default' => '2.99' | |
| 1644 | - ); | |
| 1645 | - $this->instance_form_fields['free_shipping_min_amount'] = array( | |
| 1646 | - 'title' => __('Free shipping amount', 'wc_makecommerce_domain'), | |
| 1647 | - 'type' => 'number', | |
| 1648 | - 'default' => '0', | |
| 1649 | - 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1650 | - ); | |
| 1651 | - | |
| 1652 | 1496 | $this->form_fields = array(); |
| 1653 | 1497 | $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); |
| 1654 | 1498 | $this->form_fields['generic'] = array( |
| 1655 | 1499 | 'type' => 'title', |
| @@ -1661,28 +1505,58 @@ | ||
| 1661 | 1505 | 'type' => 'checkbox', |
| 1662 | 1506 | 'label' => __('enabled', 'wc_makecommerce_domain'), |
| 1663 | 1507 | 'default' => 'no', |
| 1664 | 1508 | ); |
| 1509 | + $this->form_fields['countries'] = array( | |
| 1510 | + 'title' => __('Enable Shipping to', 'wc_makecommerce_domain'), | |
| 1511 | + 'type' => 'multiselect', | |
| 1512 | + 'class' => 'wp-enhanced-select', | |
| 1513 | + 'css' => 'width: 450px;', | |
| 1514 | + 'default' => array('EE','LV','LT'), | |
| 1515 | + 'options' => array('EE' => __('Estonia - EE'), 'LV' => __('Latvia - LV'), 'LT' => __('Lithuania - LT')), | |
| 1516 | + 'description' => __('use Shift key to select multiple lines', 'wc_makecommerce_domain'), | |
| 1517 | + ); | |
| 1518 | + $this->form_fields['price_ee'] = array( | |
| 1519 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' EE', | |
| 1520 | + 'type' => 'text', | |
| 1521 | + 'default' => '2.99' | |
| 1522 | + ); | |
| 1523 | + $this->form_fields['free_shipping_min_amount_ee'] = array( | |
| 1524 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' EE', | |
| 1525 | + 'type' => 'number', | |
| 1526 | + 'default' => '0', | |
| 1527 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1528 | + ); | |
| 1529 | + $this->form_fields['price_lv'] = array( | |
| 1530 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' LV', | |
| 1531 | + 'type' => 'text', | |
| 1532 | + 'default' => '7.99' | |
| 1533 | + ); | |
| 1534 | + $this->form_fields['free_shipping_min_amount_lv'] = array( | |
| 1535 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' LV', | |
| 1536 | + 'type' => 'number', | |
| 1537 | + 'default' => '0', | |
| 1538 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1539 | + ); | |
| 1540 | + $this->form_fields['price_lt'] = array( | |
| 1541 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' LT', | |
| 1542 | + 'type' => 'text', | |
| 1543 | + 'default' => '8.99' | |
| 1544 | + ); | |
| 1545 | + $this->form_fields['free_shipping_min_amount_lt'] = array( | |
| 1546 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' LT', | |
| 1547 | + 'type' => 'number', | |
| 1548 | + 'default' => '0', | |
| 1549 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1550 | + ); | |
| 1665 | 1551 | $this->form_fields['maximum_weight'] = array( |
| 1666 | - 'title' => sprintf(__('Maximum weight allowed for shipping (%s)', 'wc_makecommerce_domain'), get_option('woocommerce_weight_unit' )), | |
| 1552 | + 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'), | |
| 1667 | 1553 | 'type' => 'text', |
| 1668 | - 'default' => '30' | |
| 1554 | + 'default' => '15' | |
| 1669 | 1555 | ); |
| 1670 | 1556 | |
| 1671 | 1557 | $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on check-out page', 'wc_makecommerce_domain')); |
| 1672 | - | |
| 1673 | - if ( function_exists('icl_object_id') && ! defined( 'POLYLANG_VERSION' ) ) { | |
| 1674 | - $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 1675 | - } | |
| 1676 | - else if ( defined( 'POLYLANG_VERSION' ) ) { | |
| 1677 | - $pl_locales = pll_languages_list( array('fields'=>'locale') ); | |
| 1678 | - foreach ($pl_locales as $key => $locale_pl ) { | |
| 1679 | - $language = array( 'id' => $key, | |
| 1680 | - 'code' => $locale_pl) ; | |
| 1681 | - $languages[$locale_pl] = $language; | |
| 1682 | - } | |
| 1683 | - } | |
| 1684 | - | |
| 1558 | + $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 1685 | 1559 | if (empty($languages)) { |
| 1686 | 1560 | $this->form_fields['method_name'] = array( |
| 1687 | 1561 | 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'), |
| 1688 | 1562 | 'type' => 'text', |
| @@ -1736,96 +1610,82 @@ | ||
| 1736 | 1610 | 'type' => 'text', |
| 1737 | 1611 | 'title' => __('Shop email', 'wc_makecommerce_domain'), |
| 1738 | 1612 | 'class' => 'input-text regular-input', |
| 1739 | 1613 | ); |
| 1740 | - $this->form_fields['shop_address_country'] = array( | |
| 1741 | - 'type' => 'text', | |
| 1742 | - 'title' => __('Shop address country', 'wc_makecommerce_domain'), | |
| 1743 | - 'description' => __('Put here short country code, i.e. EE, LV, FI', 'wc_makecommerce_domain'), | |
| 1744 | - 'class' => 'input-text regular-input', | |
| 1745 | - ); | |
| 1746 | 1614 | $this->form_fields['shop_address_city'] = array( |
| 1747 | 1615 | 'type' => 'text', |
| 1748 | 1616 | 'title' => __('Shop address city', 'wc_makecommerce_domain'), |
| 1749 | 1617 | 'class' => 'input-text regular-input', |
| 1750 | 1618 | ); |
| 1751 | - $this->form_fields['shop_address_street'] = array( | |
| 1752 | - 'type' => 'text', | |
| 1753 | - 'title' => __('Shop address street', 'wc_makecommerce_domain'), | |
| 1754 | - 'class' => 'input-text regular-input', | |
| 1755 | - ); | |
| 1756 | 1619 | $this->form_fields['shop_postal_code'] = array( |
| 1757 | 1620 | 'type' => 'text', |
| 1758 | 1621 | 'title' => __('Shop postal code', 'wc_makecommerce_domain'), |
| 1759 | 1622 | 'class' => 'input-text regular-input', |
| 1623 | + 'description' => __('Put here zip-code of the Parcel Terminal you use for returns, see: <a href="https://www.omniva.ee/era/kaart/asukohad">List of Omniva Terminals</a>', 'wc_makecommerce_domain') | |
| 1760 | 1624 | ); |
| 1761 | 1625 | $this->form_fields['shipping_ui_javascript'] = array( |
| 1762 | 1626 | 'type' => 'shipping_ui_javascript', |
| 1763 | 1627 | ); |
| 1764 | 1628 | } |
| 1629 | + | |
| 1765 | 1630 | } |
| 1766 | - | |
| 1767 | 1631 | class WC_ParcelMachine_Shipping_Method_Smartpost extends WC_ParcelMachine_Shipping_Method { |
| 1768 | - function __construct($instance_id = 0) { | |
| 1632 | + function __construct() { | |
| 1769 | 1633 | $this->ext = 'SmartPost'; |
| 1770 | 1634 | $this->name_ext = 'SmartPOST'; |
| 1771 | - $this->carrier = 'smartpost'; | |
| 1772 | - $this->type = 'apt'; | |
| 1773 | - parent::__construct($instance_id); | |
| 1635 | + parent::__construct(); | |
| 1774 | 1636 | } |
| 1775 | 1637 | function init_form_fields() { |
| 1776 | - | |
| 1777 | 1638 | global $woocommerce; |
| 1778 | 1639 | |
| 1779 | - $this->instance_form_fields = array(); | |
| 1780 | - $this->instance_form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 1781 | - | |
| 1782 | - $this->instance_form_fields['price'] = array( | |
| 1783 | - 'title' => __('Shipping price', 'wc_makecommerce_domain'), | |
| 1640 | + $this->form_fields = array(); | |
| 1641 | + $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 1642 | + $this->form_fields['generic'] = array( 'type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain')); | |
| 1643 | + $this->form_fields['active'] = array( | |
| 1644 | + 'title' => __('Enable', 'wc_makecommerce_domain'), | |
| 1645 | + 'type' => 'checkbox', | |
| 1646 | + 'label' => __('enabled', 'wc_makecommerce_domain'), | |
| 1647 | + 'default' => 'no', | |
| 1648 | + 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options', 'wc_makecommerce_domain'), | |
| 1649 | + ); | |
| 1650 | + $this->form_fields['countries'] = array( | |
| 1651 | + 'title' => __('Specific Countries', 'wc_makecommerce_domain'), | |
| 1652 | + 'type' => 'multiselect', | |
| 1653 | + 'class' => 'wp-enhanced-select', | |
| 1654 | + 'css' => 'width: 450px;', | |
| 1655 | + 'default' => array('EE','FI'), | |
| 1656 | + 'options' => array('EE' => __('Estonia - EE'), 'FI' => __('Finland - FI')), | |
| 1657 | + ); | |
| 1658 | + $this->form_fields['price_ee'] = array( | |
| 1659 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' EE', | |
| 1784 | 1660 | 'type' => 'text', |
| 1785 | 1661 | 'default' => '2.99' |
| 1786 | 1662 | ); |
| 1787 | - $this->instance_form_fields['free_shipping_min_amount'] = array( | |
| 1788 | - 'title' => __('Free shipping amount', 'wc_makecommerce_domain'), | |
| 1663 | + $this->form_fields['free_shipping_min_amount_ee'] = array( | |
| 1664 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' EE', | |
| 1789 | 1665 | 'type' => 'number', |
| 1790 | 1666 | 'default' => '0', |
| 1791 | 1667 | 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), |
| 1792 | 1668 | ); |
| 1793 | - | |
| 1794 | - $this->form_fields = array(); | |
| 1795 | - $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 1796 | - $this->form_fields['generic'] = array( | |
| 1797 | - 'type' => 'title', | |
| 1798 | - 'title' => __('Generic and pricing options', 'wc_makecommerce_domain'), | |
| 1799 | - 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options.', 'wc_makecommerce_domain').'<br>'.__('You can mark there also a product as "Free shipping in parcel machine."', 'wc_makecommerce_domain'), | |
| 1669 | + $this->form_fields['price_fi'] = array( | |
| 1670 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' FI', | |
| 1671 | + 'type' => 'text', | |
| 1672 | + 'default' => '10.99' | |
| 1800 | 1673 | ); |
| 1801 | - | |
| 1802 | - $this->form_fields['active'] = array( | |
| 1803 | - 'title' => __('Enable', 'wc_makecommerce_domain'), | |
| 1804 | - 'type' => 'checkbox', | |
| 1805 | - 'label' => __('enabled', 'wc_makecommerce_domain'), | |
| 1806 | - 'default' => 'no', | |
| 1674 | + $this->form_fields['free_shipping_min_amount_fi'] = array( | |
| 1675 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain'). ' FI', | |
| 1676 | + 'type' => 'number', | |
| 1677 | + 'default' => '0', | |
| 1678 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1807 | 1679 | ); |
| 1808 | 1680 | $this->form_fields['maximum_weight'] = array( |
| 1809 | - 'title' => sprintf(__('Maximum weight allowed for shipping (%s)', 'wc_makecommerce_domain'), get_option('woocommerce_weight_unit' )), | |
| 1681 | + 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'), | |
| 1810 | 1682 | 'type' => 'text', |
| 1811 | - 'default' => '30' | |
| 1683 | + 'default' => '15' | |
| 1812 | 1684 | ); |
| 1813 | 1685 | |
| 1814 | - $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on checkout page', 'wc_makecommerce_domain')); | |
| 1815 | - | |
| 1816 | - if ( function_exists('icl_object_id') && ! defined( 'POLYLANG_VERSION' ) ) { | |
| 1817 | - $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 1818 | - } | |
| 1819 | - else if ( defined( 'POLYLANG_VERSION' ) ) { | |
| 1820 | - $pl_locales = pll_languages_list( array('fields'=>'locale') ); | |
| 1821 | - foreach ($pl_locales as $key => $locale_pl ) { | |
| 1822 | - $language = array( 'id' => $key, | |
| 1823 | - 'code' => $locale_pl) ; | |
| 1824 | - $languages[$locale_pl] = $language; | |
| 1825 | - } | |
| 1826 | - } | |
| 1827 | - | |
| 1686 | + $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => '<br>'.__('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on checkout page', 'wc_makecommerce_domain')); | |
| 1687 | + $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 1828 | 1688 | if (empty($languages)) { |
| 1829 | 1689 | $this->form_fields['method_name'] = array( |
| 1830 | 1690 | 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'), |
| 1831 | 1691 | 'type' => 'text', |
| @@ -1852,9 +1712,9 @@ | ||
| 1852 | 1712 | 'type' => 'checkbox', |
| 1853 | 1713 | 'label' => __('Display only parcel machine names, without addresses', 'wc_makecommerce_domain'), |
| 1854 | 1714 | 'default' => 'no' |
| 1855 | 1715 | ); |
| 1856 | - $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into smartpost.ee system and print the out the package labels right here, at the shop orders view. <br> Please set your smartpost.ee account credentials below here. <br>(See more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))); | |
| 1716 | + $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into smartpost.ee system and print the out the package labels right here, at the shop orders view. <br> Please set your smartpost.ee account credentials below here. <br>(See more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))); | |
| 1857 | 1717 | $this->form_fields['service_user'] = array( |
| 1858 | 1718 | 'title' => __('eteenindus.smartpost.ee username', 'wc_makecommerce_domain'), |
| 1859 | 1719 | 'type' => 'text', |
| 1860 | 1720 | 'default' => '' |
| @@ -1883,315 +1743,26 @@ | ||
| 1883 | 1743 | $this->form_fields['shipping_ui_javascript'] = array( |
| 1884 | 1744 | 'type' => 'shipping_ui_javascript', |
| 1885 | 1745 | ); |
| 1886 | 1746 | } |
| 1887 | - } | |
| 1888 | 1747 | |
| 1889 | - if (($cur_ver = get_site_option('wc_mc_version', 0)) < WC_MC_VERSION) { | |
| 1890 | - error_log("Need to update from [{$cur_ver}] to [".WC_MC_VERSION."]"); | |
| 1891 | - if (WC_MC_VERSION === 2.0) { | |
| 1892 | - // Check if omniva / smartpost is enabled and in which countries | |
| 1893 | - // Convert to shipping zone | |
| 1894 | - foreach (array('parcelmachine_omniva' => 'WC_ParcelMachine_Shipping_Method_Omniva', 'parcelmachine_smartpost' => 'WC_ParcelMachine_Shipping_Method_SmartPost') as $method_name => $method_class) { | |
| 1895 | - $transport_class_omniva = new $method_class(); | |
| 1896 | - if ($transport_class_omniva->enable === 'yes') { | |
| 1897 | - $zones = WC_Shipping_Zones::get_zones(); | |
| 1898 | - foreach ($transport_class_omniva->countries as $ecountry) { | |
| 1899 | - $has_ecountry = false; | |
| 1900 | - foreach ($zones as $zone) { | |
| 1901 | - foreach ($zone['zone_locations'] as $location) { | |
| 1902 | - if ($location->code === $ecountry) { | |
| 1903 | - $has_ecountry = $zone['zone_id']; | |
| 1904 | - foreach ($zone['shipping_methods'] as $method) { | |
| 1905 | - if ($method->id === $method_name) { | |
| 1906 | - continue 4; | |
| 1907 | - } | |
| 1908 | - } | |
| 1909 | - } | |
| 1910 | - } | |
| 1911 | - } | |
| 1912 | - if (!$has_ecountry) { | |
| 1913 | - $zone = new WC_Shipping_Zone(); | |
| 1914 | - $zone->set_zone_name($ecountry); | |
| 1915 | - $zone->add_location($ecountry, 'country'); | |
| 1916 | - $zone->save(); | |
| 1917 | - } else { | |
| 1918 | - $zone = new WC_Shipping_Zone($has_ecountry); | |
| 1919 | - } | |
| 1920 | - $instance_id = $zone->add_shipping_method($method_name); | |
| 1921 | - $transport_class = new $method_class($instance_id); | |
| 1922 | - $price = !empty($transport_class->settings['price_'.strtolower($ecountry)]) ? $transport_class->settings['price_'.strtolower($ecountry)] : 0; | |
| 1923 | - $free_shipping_min_amount = !empty($transport_class->settings['free_shipping_min_amount_'.strtolower($ecountry)]) ? $transport_class->settings['free_shipping_min_amount_'.strtolower($ecountry)] : 0; | |
| 1924 | - $transport_class->set_post_data(array($transport_class->get_field_key('price') => $price, $transport_class->get_field_key('free_shipping_min_amount') => $free_shipping_min_amount)); | |
| 1925 | - $transport_class->process_admin_options(); | |
| 1926 | - } | |
| 1927 | - } | |
| 1928 | - } | |
| 1929 | - } | |
| 1930 | - update_site_option('wc_mc_version', WC_MC_VERSION); | |
| 1931 | 1748 | } |
| 1932 | 1749 | } |
| 1933 | - | |
| 1934 | - if ( ! class_exists( 'WC_Courier_Shipping_Method_Omniva' ) ) { | |
| 1935 | - | |
| 1936 | - class WC_Courier_Shipping_Method_Omniva extends WC_Shipping_Method { | |
| 1937 | - | |
| 1938 | - public function __construct($instance_id = 0) { | |
| 1939 | - $this->ext = 'Omniva'; | |
| 1940 | - $this->name_ext = 'Omniva'; | |
| 1941 | - $this->id = 'courier_omniva'; | |
| 1942 | - $this->carrier = 'omniva'; | |
| 1943 | - $this->type = 'courier'; | |
| 1944 | - $this->instance_id = absint($instance_id); | |
| 1945 | - $this->method_title = $this->name_ext .' '.__('courier (MC)', 'wc_makecommerce_domain'); | |
| 1946 | - // $this->method_description = sprintf(__('Courier transport method for %s', 'wc_makecommerce_domain'), $this->ext); | |
| 1947 | - $this->supports = array('shipping-zones', 'instance-settings', 'instance-settings-modal', 'settings'); | |
| 1948 | - $this->init(); | |
| 1949 | - } | |
| 1950 | - | |
| 1951 | - public function init() { | |
| 1952 | - $this->init_form_fields(); | |
| 1953 | - $this->init_settings(); | |
| 1954 | - | |
| 1955 | - $this->enable = $this->settings['active']; | |
| 1956 | - if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['method_name_'.ICL_LANGUAGE_CODE])) { | |
| 1957 | - $this->title = $this->settings['method_name_'.ICL_LANGUAGE_CODE]; | |
| 1958 | - } else { | |
| 1959 | - $this->title = $this->settings['method_name']; | |
| 1960 | - } | |
| 1961 | - $this->availability = 'specific'; | |
| 1962 | - $this->free_shipping_min_amount = !empty($this->settings['free_shipping_min_amount']) ? $this->settings['free_shipping_min_amount'] : 0; | |
| 1963 | - $this->maximum_weight = (double)$this->settings['maximum_weight']; | |
| 1964 | - $this->order_country = 'unknown'; | |
| 1965 | - add_action('woocommerce_update_options_shipping_' . $this->id, array(&$this, 'process_admin_options')); | |
| 1966 | - add_filter('woocommerce_order_shipping_to_display_shipped_via', array(&$this, 'add_admin_courier_via_field')); | |
| 1967 | - | |
| 1968 | - // Woocommerce Multilingual overrides | |
| 1969 | - if ( in_array( 'woocommerce-multilingual/wpml-woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 1970 | - add_filter('woocommerce_package_rates', array($this, 'override_label_translation'), 50); | |
| 1971 | - add_filter('woocommerce_order_get_items', array($this, 'override_shipping_title_translation'), 50, 2); | |
| 1972 | - } | |
| 1973 | - } | |
| 1974 | - | |
| 1975 | - public function override_label_translation($rates) { | |
| 1976 | - $id_instance = $this->id . ':' . $this->instance_id; | |
| 1977 | - if(array_key_exists($id_instance, $rates)) { | |
| 1978 | - $rates[$id_instance]->label = $this->title; | |
| 1979 | - } | |
| 1980 | - return $rates; | |
| 1981 | - } | |
| 1982 | - | |
| 1983 | - public function override_shipping_title_translation($items, $order) { | |
| 1984 | - foreach ($items as $key => $item) { | |
| 1985 | - if($item['type'] == 'shipping') { | |
| 1986 | - foreach ($item['item_meta_array'] as $meta) { | |
| 1987 | - $tmp = explode(':', $meta->value); | |
| 1988 | - if($meta->key == 'method_id' && $tmp[0] == $this->id) { | |
| 1989 | - $items[$key]['name'] = $this->title; | |
| 1990 | - } | |
| 1991 | - } | |
| 1992 | - } | |
| 1993 | - } | |
| 1994 | - return $items; | |
| 1995 | - } | |
| 1996 | - | |
| 1997 | - public function init_form_fields() { | |
| 1998 | - | |
| 1999 | - global $woocommerce; | |
| 2000 | - | |
| 2001 | - $this->instance_form_fields = array(); | |
| 2002 | - $this->instance_form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 2003 | - $this->instance_form_fields['price'] = array( | |
| 2004 | - 'title' => __('Shipping price', 'wc_makecommerce_domain'), | |
| 2005 | - 'type' => 'text', | |
| 2006 | - 'default' => '4.95' | |
| 2007 | - ); | |
| 2008 | - $this->instance_form_fields['free_shipping_min_amount'] = array( | |
| 2009 | - 'title' => __('Free shipping amount', 'wc_makecommerce_domain'), | |
| 2010 | - 'type' => 'number', | |
| 2011 | - 'default' => '0', | |
| 2012 | - 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 2013 | - ); | |
| 2014 | - | |
| 2015 | - $this->form_fields = array(); | |
| 2016 | - $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 2017 | - $this->form_fields['generic'] = array( | |
| 2018 | - 'type' => 'title', | |
| 2019 | - 'title' => __('Generic and pricing options', 'wc_makecommerce_domain'), | |
| 2020 | - // 'description' => __('', 'wc_makecommerce_domain'), | |
| 2021 | - ); | |
| 2022 | - $this->form_fields['active'] = array( | |
| 2023 | - 'title' => __('Enable', 'wc_makecommerce_domain'), | |
| 2024 | - 'type' => 'checkbox', | |
| 2025 | - 'label' => __('enabled', 'wc_makecommerce_domain'), | |
| 2026 | - 'default' => 'no', | |
| 2027 | - ); | |
| 2028 | - $this->form_fields['maximum_weight'] = array( | |
| 2029 | - 'title' => sprintf(__('Maximum weight allowed for shipping (%s)', 'wc_makecommerce_domain'), get_option('woocommerce_weight_unit' )), | |
| 2030 | - 'type' => 'text', | |
| 2031 | - 'default' => '60' | |
| 2032 | - ); | |
| 2033 | - | |
| 2034 | - $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on check-out page', 'wc_makecommerce_domain')); | |
| 2035 | - | |
| 2036 | - if ( function_exists('icl_object_id') && ! defined( 'POLYLANG_VERSION' ) ) { | |
| 2037 | - $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 2038 | - } | |
| 2039 | - else if ( defined( 'POLYLANG_VERSION' ) ) { | |
| 2040 | - $pl_locales = pll_languages_list( array('fields'=>'locale') ); | |
| 2041 | - foreach ($pl_locales as $key => $locale_pl ) { | |
| 2042 | - $language = array( 'id' => $key, | |
| 2043 | - 'code' => $locale_pl) ; | |
| 2044 | - $languages[$locale_pl] = $language; | |
| 2045 | - } | |
| 2046 | - } | |
| 2047 | - | |
| 2048 | - if (empty($languages)) { | |
| 2049 | - $this->form_fields['method_name'] = array( | |
| 2050 | - 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'), | |
| 2051 | - 'type' => 'text', | |
| 2052 | - 'default' => __('Omniva Courier', 'wc_makecommerce_domain') | |
| 2053 | - ); | |
| 2054 | - } else { | |
| 2055 | - foreach ($languages as $language_code => $language) { | |
| 2056 | - $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code; | |
| 2057 | - $this->form_fields['method_name_'.$language_code] = array( | |
| 2058 | - 'title' => __('Shipping Method Title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code), | |
| 2059 | - 'type' => 'text', | |
| 2060 | - 'default' => __('Omniva Courier', 'wc_makecommerce_domain') | |
| 2061 | - ); | |
| 2062 | - } | |
| 2063 | - } | |
| 2064 | - | |
| 2065 | - | |
| 2066 | - $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into Omniva system and print the out the package labels right here, at the shop orders view. <br> Please set your Omniva web servises account credentials below here. <br>(see more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))); | |
| 2067 | - | |
| 2068 | - $this->form_fields['registerOnPaymentCode'] = array( | |
| 2069 | - 'title' => __('Register shipments automatically as', 'wc_makecommerce_domain'), | |
| 2070 | - 'type' => 'select', | |
| 2071 | - 'label' => __('register on Payment', 'wc_makecommerce_domain'), | |
| 2072 | - 'description' => __('Shipments will be automatically registered on payment using the selected Omniva service code', 'wc_makecommerce_domain'), | |
| 2073 | - 'options' => array( | |
| 2074 | - 'QP' => __('QP - handover to Omniva at Post Office', 'wc_makecommerce_domain'), | |
| 2075 | - 'PK' => __('PK - handover to Omniva via Parcel Machine', 'wc_makecommerce_domain'), | |
| 2076 | - '' => __('None - do not register automatically', 'wc_makecommerce_domain'), | |
| 2077 | - ), | |
| 2078 | - 'default' => 'QP', | |
| 2079 | - ); | |
| 2080 | - | |
| 2081 | - $this->form_fields['service_user'] = array( | |
| 2082 | - 'title' => __('Omniva web services username', 'wc_makecommerce_domain'), | |
| 2083 | - 'type' => 'text', | |
| 2084 | - 'default' => '' | |
| 2085 | - ); | |
| 2086 | - $this->form_fields['service_password'] = array( | |
| 2087 | - 'title' => __('Omniva web services password', 'wc_makecommerce_domain'), | |
| 2088 | - 'type' => 'text', | |
| 2089 | - 'default' => '' | |
| 2090 | - ); | |
| 2091 | - $this->form_fields['return_address'] = array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for Omniva shipments', 'wc_makecommerce_domain')); | |
| 2092 | - $this->form_fields['shop_name'] = array( | |
| 2093 | - 'type' => 'text', | |
| 2094 | - 'title' => __('Shop name', 'wc_makecommerce_domain'), | |
| 2095 | - 'class' => 'input-text regular-input', | |
| 2096 | - ); | |
| 2097 | - $this->form_fields['shop_phone'] = array( | |
| 2098 | - 'type' => 'text', | |
| 2099 | - 'title' => __('Shop phone', 'wc_makecommerce_domain'), | |
| 2100 | - 'class' => 'input-text regular-input', | |
| 2101 | - ); | |
| 2102 | - $this->form_fields['shop_email'] = array( | |
| 2103 | - 'type' => 'text', | |
| 2104 | - 'title' => __('Shop email', 'wc_makecommerce_domain'), | |
| 2105 | - 'class' => 'input-text regular-input', | |
| 2106 | - ); | |
| 2107 | - $this->form_fields['shop_address_country'] = array( | |
| 2108 | - 'type' => 'text', | |
| 2109 | - 'title' => __('Shop address country', 'wc_makecommerce_domain'), | |
| 2110 | - 'description' => __('Put here short country code, i.e. EE, LV, FI', 'wc_makecommerce_domain'), | |
| 2111 | - 'class' => 'input-text regular-input', | |
| 2112 | - ); | |
| 2113 | - $this->form_fields['shop_address_city'] = array( | |
| 2114 | - 'type' => 'text', | |
| 2115 | - 'title' => __('Shop address city', 'wc_makecommerce_domain'), | |
| 2116 | - 'class' => 'input-text regular-input', | |
| 2117 | - ); | |
| 2118 | - $this->form_fields['shop_address_street'] = array( | |
| 2119 | - 'type' => 'text', | |
| 2120 | - 'title' => __('Shop address street', 'wc_makecommerce_domain'), | |
| 2121 | - 'class' => 'input-text regular-input', | |
| 2122 | - ); | |
| 2123 | - $this->form_fields['shop_postal_code'] = array( | |
| 2124 | - 'type' => 'text', | |
| 2125 | - 'title' => __('Shop postal code', 'wc_makecommerce_domain'), | |
| 2126 | - 'class' => 'input-text regular-input', | |
| 2127 | - ); | |
| 2128 | - } | |
| 2129 | - | |
| 2130 | - public function calculate_shipping($package = array()) { | |
| 2131 | - | |
| 2132 | - $price = $this->instance_settings['price']; | |
| 2133 | - | |
| 2134 | - $free_shipping_min_amount = $this->instance_settings['free_shipping_min_amount']; | |
| 2135 | - | |
| 2136 | - if ($free_shipping_min_amount && $package['contents_cost'] >= $free_shipping_min_amount) { | |
| 2137 | - $price = 0; | |
| 2138 | - } | |
| 2139 | - | |
| 2140 | - $rate = array( | |
| 2141 | - 'id' => $this->get_rate_id(), | |
| 2142 | - 'label' => $this->title, | |
| 2143 | - 'cost' => $price, | |
| 2144 | - 'package' => $package, | |
| 2145 | - 'calc_tax' => 'per_order', | |
| 2146 | - ); | |
| 2147 | - $this->add_rate( $rate ); | |
| 2148 | - } | |
| 2149 | - | |
| 2150 | - public function calculate_weight($package) { | |
| 2151 | - $weight = 0; | |
| 2152 | - foreach ($package['contents'] as $line) { | |
| 2153 | - $weight += $line['data']->get_weight(); | |
| 2154 | - } | |
| 2155 | - return $weight; | |
| 2156 | - } | |
| 2157 | - | |
| 2158 | - public function is_available($package) { | |
| 2159 | - | |
| 2160 | - $package_weight = $this->calculate_weight($package); | |
| 2161 | - if ($package_weight >= $this->maximum_weight) { | |
| 2162 | - return false; | |
| 2163 | - } | |
| 2164 | - $is_available = $this->enable === 'yes'; | |
| 2165 | - if (!$is_available || !mk_is_api_set()) { | |
| 2166 | - return false; | |
| 2167 | - } | |
| 2168 | - | |
| 2169 | - $this->order_country = $package['destination']['country']; | |
| 2170 | - return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package); | |
| 2171 | - } | |
| 2172 | - | |
| 2173 | - public function add_admin_courier_via_field($order) { | |
| 2174 | - return ' <small>(via ' . $this->name_ext . ' ' . __('Courier', 'wc_makecommerce_domain') . ')</small>'; | |
| 2175 | - } | |
| 2176 | - } | |
| 2177 | - } | |
| 2178 | 1750 | } |
| 2179 | - add_action('woocommerce_shipping_init', 'transport_add_method'); | |
| 1751 | + add_action('woocommerce_shipping_init', 'parcelmachine_add_method'); | |
| 2180 | 1752 | |
| 2181 | - function add_mc_shipping_method($methods) { | |
| 2182 | - $methods['parcelmachine_omniva'] = 'WC_ParcelMachine_Shipping_Method_Omniva'; | |
| 2183 | - $methods['parcelmachine_smartpost'] = 'WC_ParcelMachine_Shipping_Method_Smartpost'; | |
| 2184 | - $methods['courier_omniva'] = 'WC_Courier_Shipping_Method_Omniva'; | |
| 1753 | + function add_parcelmachine_shipping_method($methods) { | |
| 1754 | + $methods[] = 'WC_ParcelMachine_Shipping_Method_Omniva'; | |
| 1755 | + $methods[] = 'WC_ParcelMachine_Shipping_Method_Smartpost'; | |
| 2185 | 1756 | return $methods; |
| 2186 | 1757 | } |
| 2187 | - add_filter('woocommerce_shipping_methods', 'add_mc_shipping_method'); | |
| 1758 | + add_filter('woocommerce_shipping_methods', 'add_parcelmachine_shipping_method'); | |
| 2188 | 1759 | |
| 2189 | - function mk_mc_add_assets() { | |
| 1760 | + function mk_parcelmachine_add_assets() { | |
| 2190 | 1761 | wp_enqueue_style('parcelmachine-css', plugin_dir_url(__FILE__).'/css/parcelmachine.css'); |
| 2191 | 1762 | wp_enqueue_script('parcelmachine-js', plugin_dir_url(__FILE__).'/scripts/parcelmachine.js', array('jquery')); |
| 2192 | 1763 | } |
| 2193 | - add_action('wp_enqueue_scripts', 'mk_mc_add_assets'); | |
| 1764 | + add_action('wp_enqueue_scripts', 'mk_parcelmachine_add_assets'); | |
| 2194 | 1765 | |
| 2195 | 1766 | function mk_admin_plugin_settings_link($links) { |
| 2196 | 1767 | $settings_link = '<a href="admin.php?page=wc-settings&tab=api§ion=mk_api">API '.__('Settings').'</a>'; |
| 2197 | 1768 | array_unshift($links, $settings_link); |
| @@ -2214,16 +1785,16 @@ | ||
| 2214 | 1785 | array('type' => 'title', 'desc' => __get_logo_html()), |
| 2215 | 1786 | array( |
| 2216 | 1787 | 'type' => 'title', |
| 2217 | 1788 | 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'), |
| 2218 | - 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain'). | |
| 2219 | - sprintf( __('To further configure the Payment methods please go to <a href="%s">MakeCommerce Checkout Options</a><br>', 'wc_makecommerce_domain'), 'admin.php?page=wc-settings&tab=checkout§ion=makecommerce'). | |
| 2220 | - sprintf( __('To use also Ominva or Itella SmartPOST integration please configure these API accesses: <a href="%s">Omniva Parcel Machine API access</a> | '. | |
| 2221 | - '<a href="%s">SmartPOST API access</a> | <a href="%s">Omniva Courier API access</a><br/>','wc_makecommerce_domain'), | |
| 2222 | - 'admin.php?page=wc-settings&tab=-shipping§ion=parcelmachine_omniva', | |
| 2223 | - 'admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_smartpost', | |
| 2224 | - 'admin.php?page=wc-settings&tab=shipping§ion=courier_omniva' | |
| 2225 | - ), | |
| 1789 | + 'desc' => sprintf(__('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>'. | |
| 1790 | + 'To further configure the Payment methods please go to <a href="%s">MakeCommerce Checkout Options</a><br>'. | |
| 1791 | + 'To use also Ominva or Itella SmartPOST integration please configure these API accesses: <a href="%s">Omniva API access</a> | '. | |
| 1792 | + '<a href="%s">SmartPOST API access</a><br/>','wc_makecommerce_domain'), | |
| 1793 | + 'admin.php?page=wc-settings&tab=checkout§ion=makecommerce', | |
| 1794 | + 'admin.php?page=wc-settings&tab=-shipping§ion=parcelmachine_omniva', | |
| 1795 | + 'admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_smartpost' | |
| 1796 | + ), | |
| 2226 | 1797 | 'id' => 'mk_api_settings' |
| 2227 | 1798 | ), |
| 2228 | 1799 | array( |
| 2229 | 1800 | 'type' => 'select', |
| @@ -2287,9 +1858,10 @@ | ||
| 2287 | 1858 | global $current_section; |
| 2288 | 1859 | if ($current_section !== 'mk_api') { |
| 2289 | 1860 | return; |
| 2290 | 1861 | } |
| 2291 | - update_mc_banklinks(); | |
| 1862 | + $wcmc = New woocommerce_makecommerce(true); | |
| 1863 | + $wcmc->mc_banklinks_reload(true); | |
| 2292 | 1864 | } |
| 2293 | 1865 | |
| 2294 | 1866 | function __get_logo_html() { |
| 2295 | 1867 | return '<div class="makecommerce-info">'. |
| @@ -2366,10 +1938,8 @@ | ||
| 2366 | 1938 | add_filter('restrict_manage_posts', 'mk_admin_restrict_manage_posts'); |
| 2367 | 1939 | add_filter('posts_where', 'mk_admin_shipping_filter', 10, 2); |
| 2368 | 1940 | |
| 2369 | 1941 | function mk_admin_bulk_actions() { |
| 2370 | - wp_enqueue_script('wc_mk_timepicker', plugins_url('/scripts/jquery-ui.timepicker.js', __FILE__)); | |
| 2371 | - wp_enqueue_style('wc_mk_timepicker-css', plugins_url('/css/jquery-ui.timepicker.css', __FILE__)); | |
| 2372 | 1942 | global $post_type; |
| 2373 | 1943 | if ('shop_order' === $post_type) { ?> |
| 2374 | 1944 | <script type="text/javascript"> |
| 2375 | 1945 | jQuery(function() { |
| @@ -2376,27 +1946,8 @@ | ||
| 2376 | 1946 | jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]'); |
| 2377 | 1947 | jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]'); |
| 2378 | 1948 | jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]'); |
| 2379 | 1949 | jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]'); |
| 2380 | - //jQuery('<option>').val('parcel_machine_order_courier').text('<?php _e( 'Order courier for parcel machine deliveries', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]'); | |
| 2381 | - //jQuery('<option>').val('parcel_machine_order_courier').text('<?php _e( 'Order courier for parcel machine deliveries', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]'); | |
| 2382 | - jQuery('select[name="action"]').after('<input type="text" name="transport_time" class="hidden timepicker"/>'); | |
| 2383 | - jQuery('select[name="action"], select[name="action2"]').on('change', function(){ | |
| 2384 | - var val = jQuery(this).val(); | |
| 2385 | - if (val === 'parcel_machine_order_courier') { | |
| 2386 | - jQuery('.timepicker').removeClass('hidden'); | |
| 2387 | - } else { | |
| 2388 | - jQuery('.timepicker').addClass('hidden'); | |
| 2389 | - } | |
| 2390 | - }); | |
| 2391 | - jQuery('.tablenav.bottom .actions.bulkactions').hide(); | |
| 2392 | - var now = new Date(); | |
| 2393 | - var mins = now.getMinutes(); | |
| 2394 | - var quarterHours = Math.ceil(mins/15); | |
| 2395 | - if (quarterHours == 4) { now.setHours(now.getHours()+1); } | |
| 2396 | - var rounded = (quarterHours*15)%60; | |
| 2397 | - now.setMinutes(rounded); | |
| 2398 | - jQuery('.timepicker').datetimepicker({dateFormat: 'dd/mm/yy', timeFormat: 'HH:mm', stepMinute: 15, minDateTime: now, devaultValue: jQuery.datepicker.formatTime('dd/mm/yyyy HH:mm', now)}); | |
| 2399 | 1950 | }); |
| 2400 | 1951 | </script> |
| 2401 | 1952 | <?php if (!empty($_REQUEST['mk_pdf'])) { ?> |
| 2402 | 1953 | <script type="text/javascript"> |
| @@ -2408,54 +1959,37 @@ | ||
| 2408 | 1959 | } |
| 2409 | 1960 | } |
| 2410 | 1961 | function mk_admin_bulk_action_labels() { |
| 2411 | 1962 | $wp_list_table = _get_list_table('WP_Posts_List_Table'); |
| 1963 | + $shipping_request = array('credentials' => array(), 'orders' => array()); | |
| 2412 | 1964 | $post_ids = array_map('absint', (array)$_REQUEST['post']); |
| 2413 | 1965 | mk_get_shipment_ids($post_ids); |
| 2414 | 1966 | } |
| 2415 | 1967 | function mk_admin_bulk_action_print() { |
| 2416 | 1968 | $wp_list_table = _get_list_table('WP_Posts_List_Table'); |
| 1969 | + $shipping_request = array('credentials' => array(), 'orders' => array()); | |
| 2417 | 1970 | $post_ids = array_map('absint', (array)$_REQUEST['post']); |
| 2418 | 1971 | mk_get_labels($post_ids); |
| 2419 | 1972 | } |
| 2420 | - function mk_admin_bulk_action_order_courier() { | |
| 2421 | - return; | |
| 2422 | - $wp_list_table = _get_list_table('WP_Posts_List_Table'); | |
| 2423 | - $post_ids = array_map('absint', (array)$_REQUEST['post']); | |
| 2424 | - $transport_time = !empty($_REQUEST['transport_time']) ? strtotime(str_replace('/', '-', $_REQUEST['transport_time'])) : false; | |
| 2425 | - if ($transport_time && $transport_time > time()) { | |
| 2426 | - mk_get_shipment_ids($post_ids, 'omniva'); | |
| 2427 | - } else { | |
| 2428 | - die('Please select transport time that is in the future'); | |
| 2429 | - } | |
| 2430 | - } | |
| 2431 | 1973 | add_action('admin_footer', 'mk_admin_bulk_actions', 11); |
| 2432 | 1974 | add_action('admin_action_parcel_machine_labels', 'mk_admin_bulk_action_labels'); |
| 2433 | 1975 | add_action('admin_action_parcel_machine_print_labels', 'mk_admin_bulk_action_print'); |
| 2434 | - add_action('admin_action_parcel_machine_order_courier', 'mk_admin_bulk_action_order_courier'); | |
| 2435 | 1976 | |
| 2436 | 1977 | |
| 2437 | 1978 | |
| 2438 | 1979 | function mk_admin_parcelmachine_order_meta($order) { |
| 2439 | 1980 | $machine_id = get_post_meta($order->id, '_parcel_machine', true); |
| 2440 | - if (!empty($machine_id)) { | |
| 2441 | - list($carrier, $machine) = explode('||', $machine_id); | |
| 2442 | - if (!empty($machine)) { | |
| 2443 | - $machine = mk_get_machine($carrier, (int)$machine); | |
| 2444 | - if ($machine) { | |
| 2445 | - echo '<p><strong>'.__('Parcel machine').':</strong><br/>' . $machine['name'] . '<br/><small>' . $machine['address'] . '</small></p>'; | |
| 2446 | - } | |
| 2447 | - } | |
| 2448 | - } | |
| 1981 | + if (empty($machine_id)) return; | |
| 1982 | + list($provider, $machine) = explode('||', $machine_id); | |
| 1983 | + if (empty($machine)) return; | |
| 1984 | + $machine = mk_get_machine($provider, (int)$machine); | |
| 1985 | + if (!$machine) return; | |
| 1986 | + echo '<p><strong>'.__('Parcel machine').':</strong><br/>' . $machine['name'] . '<br/><small>' . $machine['address'] . '</small></p>'; | |
| 2449 | 1987 | $shipment_id = get_post_meta($order->id, '_parcel_machine_shipment_id', true); |
| 2450 | 1988 | $shipment_id_error = get_post_meta($order->id, '_parcel_machine_error', true); |
| 2451 | - $shipment_manifest = get_post_meta($order->id, '_parcel_machine_manifest', true); | |
| 2452 | 1989 | if ($shipment_id) { |
| 2453 | - echo '<p><strong>'.__('Shipment tracking code').':</strong><br/>' . $shipment_id . '</small></p>'; | |
| 1990 | + echo '<p><strong>'.__('Parcel machine shipment ID').':</strong><br/>' . $shipment_id . '</small></p>'; | |
| 2454 | 1991 | } |
| 2455 | - if ($shipment_manifest) { | |
| 2456 | - echo '<p><strong>'.__('Parcel machine pickup manifest').':</strong><br/><a href="' . $shipment_manifest . '" target="_blank">link</a></small></p>'; | |
| 2457 | - } | |
| 2458 | 1992 | if ($shipment_id_error) { |
| 2459 | 1993 | echo '<p><strong style="color: red;">'.__('Parcel machine shipment generation error').':</strong><br/>' . $shipment_id_error . '</small></p>'; |
| 2460 | 1994 | } |
| 2461 | 1995 | } |
| @@ -2468,21 +2002,21 @@ | ||
| 2468 | 2002 | if ($column === 'shipping_address') { |
| 2469 | 2003 | $machine = get_post_meta($the_order->id, '_parcel_machine', true); |
| 2470 | 2004 | $shipment_id = get_post_meta($the_order->id, '_parcel_machine_shipment_id', true); |
| 2471 | 2005 | $shipment_id_error = get_post_meta($the_order->id, '_parcel_machine_error', true); |
| 2472 | - if ($machine && !$shipment_id) { | |
| 2473 | - //echo __('Shipment ID not generated for delivery', 'wc_makecommerce_domain'); | |
| 2006 | + if ($machine) { | |
| 2007 | + if ($shipment_id) echo __('Package shipment_id:', 'wc_makecommerce_domain') . ' ' . $shipment_id; | |
| 2008 | + else if ($shipment_id_error) echo '<span style="color: red;">'.__('Package shipment generation error:', 'wc_makecommerce_domain') . '</span><br/>' .$shipment_id_error; | |
| 2009 | + else echo __('Shipment ID not generated for delivery', 'wc_makecommerce_domain'); | |
| 2474 | 2010 | } |
| 2475 | - if ($shipment_id) echo __('Shipment tracking code', 'wc_makecommerce_domain') . ': ' . $shipment_id; | |
| 2476 | - else if ($shipment_id_error) echo '<span style="color: red;">'.__('Package shipment generation error:', 'wc_makecommerce_domain') . '</span><br/>' .$shipment_id_error; | |
| 2477 | 2011 | } |
| 2478 | 2012 | } |
| 2479 | 2013 | function mk_add_email_customer_details_fields($fields, $sent_to_admin, $order) { |
| 2480 | 2014 | $machine_id = get_post_meta($order->id, '_parcel_machine', true); |
| 2481 | 2015 | if (empty($machine_id)) return $fields; |
| 2482 | - list($carrier, $machine) = explode('||', $machine_id); | |
| 2016 | + list($provider, $machine) = explode('||', $machine_id); | |
| 2483 | 2017 | if (empty($machine)) return $fields; |
| 2484 | - $machine = mk_get_machine($carrier, (int)$machine); | |
| 2018 | + $machine = mk_get_machine($provider, (int)$machine); | |
| 2485 | 2019 | if (!$machine) return $fields; |
| 2486 | 2020 | $fields[] = array('label' => __('Parcel machine'), 'value' => $machine['name'].' - '.$machine['address']); |
| 2487 | 2021 | return $fields; |
| 2488 | 2022 | } |
| @@ -2488,11 +2022,11 @@ | ||
| 2488 | 2022 | } |
| 2489 | 2023 | function mk_add_order_customer_details_fields($order) { |
| 2490 | 2024 | $machine_id = get_post_meta($order->id, '_parcel_machine', true); |
| 2491 | 2025 | if (empty($machine_id)) return; |
| 2492 | - list($carrier, $machine) = explode('||', $machine_id); | |
| 2026 | + list($provider, $machine) = explode('||', $machine_id); | |
| 2493 | 2027 | if (empty($machine)) return; |
| 2494 | - $machine = mk_get_machine($carrier, (int)$machine); | |
| 2028 | + $machine = mk_get_machine($provider, (int)$machine); | |
| 2495 | 2029 | if (!$machine) return; |
| 2496 | 2030 | echo '<tr>'; |
| 2497 | 2031 | echo '<th>'.__('Parcel machine').'</th>'; |
| 2498 | 2032 | echo '<td>'.$machine['name'].'<br/>'.$machine['address'].'</td>'; |
| @@ -2534,92 +2068,53 @@ | ||
| 2534 | 2068 | add_action('woocommerce_order_status_processing', 'mk_get_shipment_ids'); |
| 2535 | 2069 | |
| 2536 | 2070 | |
| 2537 | 2071 | |
| 2538 | - function mk_get_shipment_ids($post_ids, $select_carrier = null) { | |
| 2072 | + function mk_get_shipment_ids($post_ids) { | |
| 2539 | 2073 | if (!is_array($post_ids)) { |
| 2540 | 2074 | $post_ids = array($post_ids); |
| 2541 | 2075 | } |
| 2542 | - transport_add_method(); | |
| 2076 | + parcelmachine_add_method(); | |
| 2543 | 2077 | $shipping_request = array('credentials' => array(), 'orders' => array()); |
| 2544 | - $shipping_classes_map = array( | |
| 2545 | - 'parcelmachine_omniva' => 'WC_ParcelMachine_Shipping_Method_Omniva', | |
| 2546 | - 'parcelmachine_smartpost' => 'WC_ParcelMachine_Shipping_Method_Smartpost', | |
| 2547 | - 'courier_omniva' => 'WC_Courier_Shipping_Method_Omniva' | |
| 2548 | - ); | |
| 2549 | 2078 | foreach ($post_ids as $post_id) { |
| 2550 | - $order = new WC_Order($post_id); | |
| 2551 | - $shipping_methods = $order->get_shipping_methods(); | |
| 2552 | - if (empty($shipping_methods)) { continue; } | |
| 2553 | - foreach ($shipping_methods as $shipping_method) { | |
| 2554 | - $shipping_id = explode(':', $shipping_method['method_id']); | |
| 2555 | - $shipping_class = $shipping_id[0]; | |
| 2556 | - $shipping_instance = !empty($shipping_id[1]) ? $shipping_id[1] : null; | |
| 2557 | - if (empty($shipping_classes_map[$shipping_class])) { | |
| 2079 | + $parcel_machine = get_post_meta($post_id, '_parcel_machine', true); | |
| 2080 | + if (!$parcel_machine) { continue; } | |
| 2081 | + list($provider, $machine_id) = explode('||', $parcel_machine); | |
| 2082 | + if (!$provider || !$machine_id) { continue; } | |
| 2083 | + $provider_uc = mb_strtoupper($provider); | |
| 2084 | + switch ($provider_uc) { | |
| 2085 | + case "OMNIVA": | |
| 2086 | + $transport_class = new WC_ParcelMachine_Shipping_Method_Omniva(); | |
| 2087 | + break; | |
| 2088 | + case "SMARTPOST": | |
| 2089 | + $transport_class = new WC_ParcelMachine_Shipping_Method_Smartpost(); | |
| 2090 | + break; | |
| 2091 | + default: | |
| 2092 | + break 2; | |
| 2093 | + } | |
| 2094 | + if (empty($shipping_request['credentials'][$provider_uc])) { | |
| 2095 | + $api_user = $transport_class->settings['service_user']; | |
| 2096 | + $api_password = $transport_class->settings['service_password']; | |
| 2097 | + if (!$api_user || !$api_password) { | |
| 2098 | + add_action('admin_notices', 'mk_admin_error'); | |
| 2558 | 2099 | continue; |
| 2559 | 2100 | } |
| 2560 | - | |
| 2561 | - $transport_class = new $shipping_classes_map[$shipping_class]($shipping_instance); | |
| 2562 | - $carrier_uc = mb_strtoupper($transport_class->carrier); | |
| 2563 | - | |
| 2564 | - if ($transport_class->type === 'apt') { | |
| 2565 | - $parcel_machine = get_post_meta($post_id, '_parcel_machine', true); | |
| 2566 | - if (!$parcel_machine) { continue; } | |
| 2567 | - list($carrier, $machine_id) = explode('||', $parcel_machine); | |
| 2568 | - if (!$carrier || !$machine_id) { continue; } | |
| 2569 | - } | |
| 2570 | - | |
| 2571 | - if (empty($shipping_request['credentials'][$carrier_uc])) { | |
| 2572 | - $api_user = $transport_class->settings['service_user']; | |
| 2573 | - $api_password = $transport_class->settings['service_password']; | |
| 2574 | - if (!$api_user || !$api_password) { | |
| 2575 | - add_action('admin_notices', 'mk_admin_error'); | |
| 2576 | - continue; | |
| 2577 | - } | |
| 2578 | - $shipping_request['credentials'][$carrier_uc] = array('carrier' => $carrier_uc, 'username' => $api_user, 'password' => $api_password); | |
| 2579 | - } | |
| 2580 | - $sender = array( | |
| 2581 | - 'name' => !empty($transport_class->settings['shop_name']) ? $transport_class->settings['shop_name'] : '', | |
| 2582 | - 'phone' => !empty($transport_class->settings['shop_phone']) ? $transport_class->settings['shop_phone'] : '', | |
| 2583 | - 'email' => !empty($transport_class->settings['shop_email']) ? $transport_class->settings['shop_email'] : '', | |
| 2584 | - 'country' => !empty($transport_class->settings['shop_address_country']) ? $transport_class->settings['shop_address_country'] : '', | |
| 2585 | - 'city' => !empty($transport_class->settings['shop_address_city']) ? $transport_class->settings['shop_address_city'] : '', | |
| 2586 | - 'street' => !empty($transport_class->settings['shop_address_street']) ? $transport_class->settings['shop_address_street'] : '', | |
| 2587 | - 'postalCode' => !empty($transport_class->settings['shop_postal_code']) ? $transport_class->settings['shop_postal_code'] : '' | |
| 2588 | - ); | |
| 2589 | - $sr_order = array( | |
| 2590 | - 'carrier' => $carrier_uc, | |
| 2591 | - 'orderId' => $order->id, | |
| 2592 | - 'recipient' => array('name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'phone' => $order->billing_phone, 'email' => $order->billing_email), | |
| 2593 | - 'sender' => $sender, | |
| 2594 | - 'destination' => array(), | |
| 2595 | - ); | |
| 2596 | - $m_service_type = null; | |
| 2597 | - if ($transport_class->carrier === 'omniva' && $transport_class->type === 'atp') { | |
| 2598 | - $m_service_type = 'PA'; | |
| 2599 | - } else if (!empty($transport_class->settings['registerOnPaymentCode'])) { | |
| 2600 | - $m_service_type = $transport_class->settings['registerOnPaymentCode']; | |
| 2601 | - } | |
| 2602 | - | |
| 2603 | - if (!empty($machine_id)) { | |
| 2604 | - $sr_order['destination']['destinationId'] = $machine_id; | |
| 2605 | - } | |
| 2606 | - if ($transport_class->carrier === 'omniva' && $transport_class->type === 'courier') { | |
| 2607 | - $sr_order['destination'] = array( | |
| 2608 | - 'postalCode' => $order->shipping_postcode, | |
| 2609 | - 'country' => $order->shipping_country, | |
| 2610 | - 'county' => $order->shipping_state, | |
| 2611 | - 'city' => $order->shipping_city, | |
| 2612 | - 'street' => $order->shipping_address_1 . ' ' . $order->shipping_address_2 | |
| 2613 | - ); | |
| 2614 | - } | |
| 2615 | - | |
| 2616 | - if ($m_service_type) { | |
| 2617 | - $sr_order['services'] = array('serviceType' => $m_service_type); | |
| 2618 | - } | |
| 2619 | - | |
| 2620 | - $shipping_request['orders'][] = $sr_order; | |
| 2101 | + $shipping_request['credentials'][$provider_uc] = array('carrier' => $provider_uc, 'username' => $api_user, 'password' => $api_password); | |
| 2621 | 2102 | } |
| 2103 | + $order = wc_get_order($post_id); | |
| 2104 | + $sender = array( | |
| 2105 | + 'name' => $transport_class->settings['shop_name'], | |
| 2106 | + 'phone' => $transport_class->settings['shop_phone'], | |
| 2107 | + 'email' => $transport_class->settings['shop_email'], | |
| 2108 | + 'postalCode' => $transport_class->settings['shop_postal_code'] | |
| 2109 | + ); | |
| 2110 | + $shipping_request['orders'][] = array( | |
| 2111 | + 'carrier' => $provider_uc, | |
| 2112 | + 'orderId' => $order->id, | |
| 2113 | + 'destination' => array('destinationId' => $machine_id), | |
| 2114 | + 'recipient' => array('name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'phone' => $order->billing_phone, 'email' => $order->billing_email), | |
| 2115 | + 'sender' => $sender | |
| 2116 | + ); | |
| 2622 | 2117 | } |
| 2623 | 2118 | $shipping_request['credentials'] = array_values($shipping_request['credentials']); |
| 2624 | 2119 | if (empty($shipping_request['orders'])) { |
| 2625 | 2120 | return; |
| @@ -2633,21 +2128,13 @@ | ||
| 2633 | 2128 | } catch (Exception $e) { |
| 2634 | 2129 | echo $e->getMessage(); |
| 2635 | 2130 | exit(); |
| 2636 | 2131 | } |
| 2637 | - $shipments = !empty($response->shipments) ? $response->shipments : $response; | |
| 2638 | - $manifest = !empty($response->manifests) ? $response->manifests[0] : false; | |
| 2639 | - | |
| 2640 | - foreach ($shipments as $order) { | |
| 2641 | - if ($manifest) { | |
| 2642 | - update_post_meta((int)$order->orderId, '_parcel_machine_manifest', sanitize_text_field($manifest)); | |
| 2643 | - } | |
| 2132 | + foreach ($response as $order) { | |
| 2644 | 2133 | if (!empty($order->orderId) && !empty($order->shipmentId)) { |
| 2645 | 2134 | update_post_meta((int)$order->orderId, '_parcel_machine_shipment_id', sanitize_text_field($order->shipmentId)); |
| 2646 | - delete_post_meta((int)$order->orderId, '_parcel_machine_error'); | |
| 2647 | 2135 | } else if (!empty($order->orderId) && !empty($order->barCode)) { |
| 2648 | 2136 | update_post_meta((int)$order->orderId, '_parcel_machine_shipment_id', sanitize_text_field($order->barCode)); |
| 2649 | - delete_post_meta((int)$order->orderId, '_parcel_machine_error'); | |
| 2650 | 2137 | } else if (!empty($order->orderId) && !empty($order->errorMessage)) { |
| 2651 | 2138 | update_post_meta((int)$order->orderId, '_parcel_machine_error', sanitize_text_field($order->errorMessage)); |
| 2652 | 2139 | } |
| 2653 | 2140 | } |
| @@ -2656,89 +2143,52 @@ | ||
| 2656 | 2143 | function mk_get_labels($post_ids, $ajax = false) { |
| 2657 | 2144 | if (!is_array($post_ids)) { |
| 2658 | 2145 | $post_ids = array($post_ids); |
| 2659 | 2146 | } |
| 2660 | - transport_add_method(); | |
| 2147 | + parcelmachine_add_method(); | |
| 2661 | 2148 | $shipping_request = array('credentials' => array(), 'orders' => array(), 'printFormat' => 'A4'); |
| 2662 | - $shipping_classes_map = array( | |
| 2663 | - 'parcelmachine_omniva' => 'WC_ParcelMachine_Shipping_Method_Omniva', | |
| 2664 | - 'parcelmachine_smartpost' => 'WC_ParcelMachine_Shipping_Method_Smartpost', | |
| 2665 | - 'courier_omniva' => 'WC_Courier_Shipping_Method_Omniva' | |
| 2666 | - ); | |
| 2667 | 2149 | foreach ($post_ids as $post_id) { |
| 2668 | - $shipment_id = get_post_meta($post_id, '_parcel_machine_shipment_id', true); | |
| 2669 | - if (!$shipment_id) { continue; } | |
| 2670 | - $order = new WC_Order($post_id); | |
| 2671 | - $shipping_methods = $order->get_shipping_methods(); | |
| 2672 | - if (empty($shipping_methods)) { continue; } | |
| 2673 | - foreach ($shipping_methods as $shipping_method) { | |
| 2674 | - $shipping_id = explode(':', $shipping_method['method_id']); | |
| 2675 | - $shipping_class = $shipping_id[0]; | |
| 2676 | - $shipping_instance = !empty($shipping_id[1]) ? $shipping_id[1] : null; | |
| 2677 | - if (empty($shipping_classes_map[$shipping_class])) { | |
| 2150 | + $parcel_machine = get_post_meta($post_id, '_parcel_machine', true); | |
| 2151 | + if (!$parcel_machine) { continue; } | |
| 2152 | + list($provider, $machine_id) = explode('||', $parcel_machine); | |
| 2153 | + if (!$provider || !$machine_id) { continue; } | |
| 2154 | + $provider_uc = mb_strtoupper($provider); | |
| 2155 | + if (empty($shipping_request['credentials'][$provider_uc])) { | |
| 2156 | + switch ($provider_uc) { | |
| 2157 | + case "OMNIVA": | |
| 2158 | + $transport_class = new WC_ParcelMachine_Shipping_Method_Omniva(); | |
| 2159 | + break; | |
| 2160 | + case "SMARTPOST": | |
| 2161 | + $transport_class = new WC_ParcelMachine_Shipping_Method_Smartpost(); | |
| 2162 | + break; | |
| 2163 | + default: | |
| 2164 | + break 2; | |
| 2165 | + } | |
| 2166 | + $api_user = $transport_class->settings['service_user']; | |
| 2167 | + $api_password = $transport_class->settings['service_password']; | |
| 2168 | + if (!$api_user || !$api_password) { | |
| 2169 | + add_action('admin_notices', 'mk_admin_error'); | |
| 2678 | 2170 | continue; |
| 2679 | 2171 | } |
| 2680 | - | |
| 2681 | - $transport_class = new $shipping_classes_map[$shipping_class]($shipping_instance); | |
| 2682 | - $carrier_uc = mb_strtoupper($transport_class->carrier); | |
| 2683 | - | |
| 2684 | - if ($transport_class->type === 'apt') { | |
| 2685 | - $parcel_machine = get_post_meta($post_id, '_parcel_machine', true); | |
| 2686 | - if (!$parcel_machine) { continue; } | |
| 2687 | - list($carrier, $machine_id) = explode('||', $parcel_machine); | |
| 2688 | - if (!$carrier || !$machine_id) { continue; } | |
| 2689 | - } | |
| 2690 | - if (empty($shipping_request['credentials'][$carrier_uc])) { | |
| 2691 | - $api_user = $transport_class->settings['service_user']; | |
| 2692 | - $api_password = $transport_class->settings['service_password']; | |
| 2693 | - if (!$api_user || !$api_password) { | |
| 2694 | - add_action('admin_notices', 'mk_admin_error'); | |
| 2695 | - continue; | |
| 2696 | - } | |
| 2697 | - $shipping_request['credentials'][$carrier_uc] = array('carrier' => $carrier_uc, 'username' => $api_user, 'password' => $api_password); | |
| 2698 | - } | |
| 2699 | - $sender = array( | |
| 2700 | - 'name' => $transport_class->settings['shop_name'], | |
| 2701 | - 'phone' => $transport_class->settings['shop_phone'], | |
| 2702 | - 'email' => $transport_class->settings['shop_email'], | |
| 2703 | - 'country' => $transport_class->settings['shop_address_country'], | |
| 2704 | - 'city' => $transport_class->settings['shop_address_city'], | |
| 2705 | - 'street' => $transport_class->settings['shop_address_street'], | |
| 2706 | - 'postalCode' => $transport_class->settings['shop_postal_code'] | |
| 2707 | - ); | |
| 2708 | - $sr_order = array( | |
| 2709 | - 'carrier' => $carrier_uc, | |
| 2710 | - 'orderId' => $order->id, | |
| 2711 | - 'recipient' => array('name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'phone' => $order->billing_phone, 'email' => $order->billing_email), | |
| 2712 | - 'sender' => $sender, | |
| 2713 | - 'shipmentId' => $shipment_id | |
| 2714 | - ); | |
| 2715 | - $m_service_type = null; | |
| 2716 | - if ($transport_class->carrier === 'omniva' && $transport_class->type === 'atp') { | |
| 2717 | - $m_service_type = 'PA'; | |
| 2718 | - } else if (!empty($transport_class->settings['registerOnPaymentCode'])) { | |
| 2719 | - $m_service_type = $transport_class->settings['registerOnPaymentCode']; | |
| 2720 | - } | |
| 2721 | - | |
| 2722 | - if (!empty($machine_id)) { | |
| 2723 | - $sr_order['destination']['destinationId'] = $machine_id; | |
| 2724 | - } | |
| 2725 | - if ($transport_class->carrier === 'omniva' && $transport_class->type === 'courier') { | |
| 2726 | - $sr_order['destination'] = array( | |
| 2727 | - 'postalCode' => $order->shipping_postcode, | |
| 2728 | - 'country' => $order->shipping_country, | |
| 2729 | - 'county' => $order->shipping_state, | |
| 2730 | - 'city' => $order->shipping_city, | |
| 2731 | - 'street' => $order->shipping_address_1 . ' ' . $order->shipping_address_2 | |
| 2732 | - ); | |
| 2733 | - } | |
| 2734 | - | |
| 2735 | - if ($m_service_type) { | |
| 2736 | - $sr_order['services'] = array('serviceType' => $m_service_type); | |
| 2737 | - } | |
| 2738 | - | |
| 2739 | - $shipping_request['orders'][] = $sr_order; | |
| 2172 | + $shipping_request['credentials'][$provider_uc] = array('carrier' => $provider_uc, 'username' => $api_user, 'password' => $api_password); | |
| 2740 | 2173 | } |
| 2174 | + $order = wc_get_order($post_id); | |
| 2175 | + $shipment_id = get_post_meta($post_id, '_parcel_machine_shipment_id', true); | |
| 2176 | + if (!$shipment_id) { continue; } | |
| 2177 | + $sender = array( | |
| 2178 | + 'name' => $transport_class->settings['shop_name'], | |
| 2179 | + 'phone' => $transport_class->settings['shop_phone'], | |
| 2180 | + 'email' => $transport_class->settings['shop_email'], | |
| 2181 | + 'postalCode' => $transport_class->settings['shop_postal_code'] | |
| 2182 | + ); | |
| 2183 | + $shipping_request['orders'][] = array( | |
| 2184 | + 'carrier' => $provider_uc, | |
| 2185 | + 'orderId' => $order->id, | |
| 2186 | + 'destination' => array('destinationId' => $machine_id), | |
| 2187 | + 'recipient' => array('name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'phone' => $order->billing_phone, 'email' => $order->billing_email), | |
| 2188 | + 'sender' => $sender, | |
| 2189 | + 'shipmentId' => $shipment_id | |
| 2190 | + ); | |
| 2741 | 2191 | } |
| 2742 | 2192 | $shipping_request['credentials'] = array_values($shipping_request['credentials']); |
| 2743 | 2193 | if (empty($shipping_request['orders'])) { |
| 2744 | 2194 | return; |
| @@ -2755,9 +2205,9 @@ | ||
| 2755 | 2205 | } |
| 2756 | 2206 | if (empty($response->labelUrl)) { |
| 2757 | 2207 | return; |
| 2758 | 2208 | } |
| 2759 | - if ($ajax) { | |
| 2209 | + if($ajax) { | |
| 2760 | 2210 | return $response->labelUrl; |
| 2761 | 2211 | } |
| 2762 | 2212 | $sendback = add_query_arg(array('post_type' => 'shop_order', 'mk_pdf' => urlencode($response->labelUrl)), ''); |
| 2763 | 2213 | wp_redirect(esc_url_raw($sendback)); |
| @@ -2763,8 +2213,10 @@ | ||
| 2763 | 2213 | wp_redirect(esc_url_raw($sendback)); |
| 2764 | 2214 | exit(); |
| 2765 | 2215 | } |
| 2766 | 2216 | |
| 2217 | + | |
| 2218 | + | |
| 2767 | 2219 | $MKAPI = false; |
| 2768 | 2220 | function mk_get_api() { |
| 2769 | 2221 | global $MKAPI; |
| 2770 | 2222 | if ($MKAPI) { |
| @@ -2787,36 +2239,13 @@ | ||
| 2787 | 2239 | } |
| 2788 | 2240 | $MKAPI = new Maksekeskus($mk_shop_id, $mk_public_key, $mk_private_key, $mk_api_type === 'live' ? false : true); |
| 2789 | 2241 | return $MKAPI; |
| 2790 | 2242 | } |
| 2791 | - | |
| 2792 | - function mk_is_api_set() { | |
| 2793 | - $mk_api_type = get_option('mk_api_type', false); | |
| 2794 | - if (!$mk_api_type) { | |
| 2795 | - return false; | |
| 2796 | - } | |
| 2797 | - if ($mk_api_type !== 'live') { | |
| 2798 | - $key_prefix = $mk_api_type.'_'; | |
| 2799 | - } else { | |
| 2800 | - $key_prefix = ''; | |
| 2801 | - } | |
| 2802 | - $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', ''); | |
| 2803 | - $mk_public_key = get_option('mk_'.$key_prefix.'public_key', ''); | |
| 2804 | - $mk_private_key = get_option('mk_'.$key_prefix.'private_key', ''); | |
| 2805 | - if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) { | |
| 2806 | - return false; | |
| 2807 | - } | |
| 2808 | - return true; | |
| 2809 | - } | |
| 2810 | - | |
| 2811 | - function mk_get_machines($carrier, $country = null) { | |
| 2243 | + function mk_get_machines($provider, $country = 'EE') { | |
| 2812 | 2244 | $data = get_option('mk_machines_cache', false); |
| 2813 | 2245 | $data_expires = get_option('mk_machines_expires', false); |
| 2814 | 2246 | if (!$data || $data_expires < time()) { |
| 2815 | 2247 | $MK = mk_get_api(); |
| 2816 | - if(!$MK) { | |
| 2817 | - return array(); | |
| 2818 | - } | |
| 2819 | 2248 | $data = $MK->getDestinations(array('type' => 'APT')); |
| 2820 | 2249 | update_option('mk_machines_cache', $data); |
| 2821 | 2250 | update_option('mk_machines_expires', time()+3*60*60); |
| 2822 | 2251 | } |
| @@ -2825,11 +2254,11 @@ | ||
| 2825 | 2254 | if (!$data || empty($data)) { |
| 2826 | 2255 | return array(); |
| 2827 | 2256 | } |
| 2828 | 2257 | foreach ($data as $machine) { |
| 2829 | - if ((!$country || $machine->country === $country) && $machine->type === 'APT' && ($carrier === '*' || strtolower($carrier) === strtolower($machine->carrier))) { | |
| 2258 | + if ($machine->country === $country && $machine->type === 'APT' && ($provider === '*' || strtolower($provider) === strtolower($machine->provider))) { | |
| 2830 | 2259 | $machines[] = array( |
| 2831 | - 'carrier' => strtolower($machine->carrier), | |
| 2260 | + 'carrier' => strtolower($machine->provider), | |
| 2832 | 2261 | 'id' => $machine->id, |
| 2833 | 2262 | 'name' => $machine->name, |
| 2834 | 2263 | 'city' => $machine->city, |
| 2835 | 2264 | 'address' => !empty($machine->address) ? $machine->address : '', |
| @@ -2844,18 +2273,17 @@ | ||
| 2844 | 2273 | }); |
| 2845 | 2274 | return $machines; |
| 2846 | 2275 | } |
| 2847 | 2276 | |
| 2848 | - function mk_get_machine($carrier, $id) { | |
| 2849 | - $machines = mk_get_machines($carrier); | |
| 2277 | + function mk_get_machine($provider, $id) { | |
| 2278 | + $machines = mk_get_machines($provider); | |
| 2850 | 2279 | foreach ($machines as $machine) { |
| 2851 | - if ($machine['carrier'] === $carrier && $machine['id'] === $id) { | |
| 2280 | + if ($machine['carrier'] === $provider && $machine['id'] === $id) { | |
| 2852 | 2281 | return $machine; |
| 2853 | 2282 | } |
| 2854 | 2283 | } |
| 2855 | 2284 | return false; |
| 2856 | 2285 | } |
| 2857 | - | |
| 2858 | 2286 | function mk_admin_error() { |
| 2859 | 2287 | printf( '<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', __('Please check that you have configured correctly MakeCommerce API accesses', 'wc_makecommerce_domain')); |
| 2860 | 2288 | } |
| 2861 | 2289 | |
| @@ -2860,9 +2288,8 @@ | ||
| 2860 | 2288 | } |
| 2861 | 2289 | |
| 2862 | 2290 | add_filter('query_vars', 'mk_cron_query_vars'); |
| 2863 | 2291 | add_action('parse_request', 'mk_parse_cron_update_vars'); |
| 2864 | - | |
| 2865 | 2292 | function mk_cron_query_vars($vars) { |
| 2866 | 2293 | $vars[] = 'mk-action'; |
| 2867 | 2294 | $vars[] = 'mk-shop-id'; |
| 2868 | 2295 | $vars[] = 'mk-test-shop-id'; |
| @@ -2867,20 +2294,19 @@ | ||
| 2867 | 2294 | $vars[] = 'mk-shop-id'; |
| 2868 | 2295 | $vars[] = 'mk-test-shop-id'; |
| 2869 | 2296 | return $vars; |
| 2870 | 2297 | } |
| 2871 | - | |
| 2872 | 2298 | function mk_parse_cron_update_vars($wp) { |
| 2873 | 2299 | if (array_key_exists('mk-action', $wp->query_vars) && $wp->query_vars['mk-action'] == 'mk-update' |
| 2874 | 2300 | && (array_key_exists('mk-shop-id', $wp->query_vars) || array_key_exists('mk-test-shop-id', $wp->query_vars) ) ) { |
| 2875 | 2301 | if( (strlen($wp->query_vars['mk-shop-id']) && $wp->query_vars['mk-shop-id'] == get_option('mk_shop_id', false) ) |
| 2876 | 2302 | || (strlen($wp->query_vars['mk-test-shop-id']) && $wp->query_vars['mk-test-shop-id'] == get_option('mk_test_shop_id', false) ) ) { |
| 2877 | - update_mc_banklinks(); | |
| 2303 | + $obj = new woocommerce_makecommerce(); | |
| 2304 | + $obj->mc_banklinks_reload(true); | |
| 2878 | 2305 | exit(); |
| 2879 | 2306 | } |
| 2880 | 2307 | } |
| 2881 | 2308 | } |
| 2882 | - | |
| 2883 | 2309 | function print_parcel_machine_label_action( $post_id ) { |
| 2884 | 2310 | ?> |
| 2885 | 2311 | <li class="wide"> |
| 2886 | 2312 | <a id="print_parcel_machine_label" href="#" class="button"><?php _e('Print parcel label', 'wc_makecommerce_domain');?></a> |
| @@ -2908,9 +2334,8 @@ | ||
| 2908 | 2334 | </li> |
| 2909 | 2335 | <?php |
| 2910 | 2336 | } |
| 2911 | 2337 | add_action('woocommerce_order_actions_end', 'print_parcel_machine_label_action'); |
| 2912 | - | |
| 2913 | 2338 | function ajax_print_pml() { |
| 2914 | 2339 | if(!current_user_can('manage_woocommerce') ) { |
| 2915 | 2340 | die(); |
| 2916 | 2341 | } |
| @@ -2916,12 +2341,5 @@ | ||
| 2916 | 2341 | } |
| 2917 | 2342 | die(mk_get_labels(intval($_POST['id']), true)); |
| 2918 | 2343 | } |
| 2919 | 2344 | add_action( 'wp_ajax_print_pml', 'ajax_print_pml' ); |
| 2920 | - | |
| 2921 | - function admin_login_update($user_login, $user) { | |
| 2922 | - if(user_can( $user, 'administrator' )) { | |
| 2923 | - update_mc_banklinks(); | |
| 2924 | - } | |
| 2925 | - } | |
| 2926 | - add_action('wp_login', 'admin_login_update', 10, 2); | |
| 2927 | 2345 | } |