Guest User

Untitled

a guest
Oct 29th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.29 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.1.0.1
  8. * @ Author : DeZender
  9. * @ Release on : 29.08.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13. defined('ABSPATH') || exit('No script kiddies please!');
  14.  
  15. if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
  16. class DevVN_Woo_GHTK_Class
  17. {
  18. static protected $instance;
  19. protected $_version = '';
  20. public $_optionName = 'devvn_woo_district';
  21. public $_optionGroup = 'devvn-district-options-group';
  22. public $_defaultOptions = [
  23. 'active_village' => '',
  24. 'required_village' => '',
  25. 'to_vnd' => '',
  26. 'remove_methob_title' => '',
  27. 'freeship_remove_other_methob' => '',
  28. 'khoiluong_quydoi' => '6000',
  29. 'active_vnd2usd' => 0,
  30. 'vnd_usd_rate' => '22745',
  31. 'vnd2usd_currency' => 'USD',
  32. 'shop_store' => [],
  33. 'token_key' => '',
  34. 'is_freeship' => 0,
  35. 'is_sandbox' => 0,
  36. 'transport' => 'road',
  37. 'active_orderstyle' => 0,
  38. 'ghtk_hash' => '',
  39. 'alepay_support' => 0,
  40. 'enable_postcode' => 0,
  41. 'enable_gender' => 0,
  42. 'print_logo' => '',
  43. 'print_note' => '<strong>Chú ý:</strong> Kiểm tra hàng khi có mặt shiper.',
  44. 'mashop' => '',
  45. 'license_key' => '',
  46. 'send_shipid_active' => 0,
  47. 'send_shipid_title' => 'Mã vận đơn tại {site_title}',
  48. 'send_shipid_content' => 'Đơn hàng #{order_id} của bạn đang được vận chuyển. <br>Mã vận đơn là: {ship_id}<br> Ngày dự kiến giao hàng: {estimated_deliver}'
  49. ];
  50. public $_default_status = [
  51. 'success' => false,
  52. 'message' => '',
  53. 'order' => ['label_id' => '', 'partner_id' => '', 'status' => '', 'created' => '', 'updated' => '', 'pick_date' => '', 'pick_period' => '', 'deliver_date' => '', 'deliver_period' => '', 'status_id' => '', 'action_time' => '', 'reason_code' => '', 'reason' => '', 'weight' => '', 'fee' => '']
  54. ];
  55. public $_weight_option = 'kilogram';
  56. public $enabled_free_shipping = '';
  57.  
  58. static public function init()
  59. {
  60. is_null(self::$instance) && (self::$instance = new self());
  61. return self::$instance;
  62. }
  63.  
  64. public function __construct()
  65. {
  66. global $ghtk_settings;
  67. $ghtk_settings = $this->get_ghtk_options();
  68. $this->set_weight_option();
  69. $this->_version = DEVVN_GHTK_VERSION_NUM;
  70. add_filter('woocommerce_checkout_fields', [$this, 'custom_override_checkout_fields'], 99999);
  71. add_filter('woocommerce_states', [$this, 'vietnam_cities_woocommerce'], 9999);
  72. add_action('woocommerce_checkout_process', [$this, 'devvn_gender_field_process']);
  73. add_action('wp_enqueue_scripts', [$this, 'devvn_enqueue_UseAjaxInWp']);
  74. add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']);
  75. add_action('wp_ajax_load_diagioihanhchinh', [$this, 'load_diagioihanhchinh_func']);
  76. add_action('wp_ajax_nopriv_load_diagioihanhchinh', [$this, 'load_diagioihanhchinh_func']);
  77. add_filter('woocommerce_localisation_address_formats', [$this, 'devvn_woocommerce_localisation_address_formats']);
  78. add_filter('woocommerce_order_formatted_billing_address', [$this, 'devvn_woocommerce_order_formatted_billing_address'], 10, 2);
  79. add_action('woocommerce_admin_order_data_after_shipping_address', [$this, 'devvn_after_shipping_address'], 10, 1);
  80. add_filter('woocommerce_order_formatted_shipping_address', [$this, 'devvn_woocommerce_order_formatted_shipping_address'], 10, 2);
  81. add_filter('woocommerce_order_details_after_customer_details', [$this, 'devvn_woocommerce_order_details_after_customer_details'], 10);
  82. add_filter('woocommerce_my_account_my_address_formatted_address', [$this, 'devvn_woocommerce_my_account_my_address_formatted_address'], 10, 3);
  83. add_filter('default_checkout_billing_country', [$this, 'devvn_change_default_checkout_country'], 999);
  84. add_filter('default_checkout_shipping_country', [$this, 'devvn_change_default_checkout_country'], 999);
  85. add_action('admin_menu', [$this, 'admin_menu']);
  86. add_action('admin_init', [$this, 'register_mysettings']);
  87. add_filter('plugin_action_links_' . DEVVN_GHTK_BASENAME, [$this, 'plugin_action_links']);
  88. add_option($this->_optionName, $this->_defaultOptions);
  89. include_once 'includes/apps.php';
  90. include_once 'includes/class-ghtk-shipping.php';
  91. add_filter('woocommerce_default_address_fields', [$this, 'devvn_custom_override_default_address_fields'], 99999);
  92. add_filter('woocommerce_get_country_locale', [$this, 'devvn_woocommerce_get_country_locale'], 99);
  93. add_filter('woocommerce_admin_billing_fields', [$this, 'devvn_woocommerce_admin_billing_fields'], 99);
  94. add_filter('woocommerce_admin_shipping_fields', [$this, 'devvn_woocommerce_admin_shipping_fields'], 99);
  95. add_filter('woocommerce_form_field_select', [$this, 'devvn_woocommerce_form_field_select'], 10, 4);
  96. add_action('woocommerce_admin_order_data_after_order_details', [$this, 'devvn_woocommerce_admin_order_data_after_order_details']);
  97. add_action('wp_ajax_dang_order_ghtk', [$this, 'func_dang_order_ghtk']);
  98. add_action('wp_ajax_print_order_ghtk', [$this, 'print_order_ghtk_func']);
  99. add_action('wp_ajax_check_status_ghtk', [$this, 'check_status_ghtk_func']);
  100. add_action('wp_ajax_ghtk_add_url', [$this, 'ghtk_add_url_func']);
  101. add_action('wp_ajax_ghtk_delete_url', [$this, 'ghtk_delete_url_func']);
  102. add_action('wp_ajax_nopriv_update_shipping_status', [$this, 'update_shipping_status_func']);
  103. add_filter('woocommerce_shipping_calculator_enable_postcode', '__return_false');
  104. add_filter('woocommerce_get_order_address', [$this, 'devvn_woocommerce_get_order_address'], 99, 2);
  105. add_filter('woocommerce_rest_prepare_shop_order_object', [$this, 'devvn_woocommerce_rest_prepare_shop_order_object'], 99, 3);
  106. include_once 'includes/updates.php';
  107. add_action('wp_ajax_inhoadon_ghtk', [$this, 'devvn_print_order']);
  108. add_action('xc_woo_cloud_print_after_order_details', [$this, 'xc_woo_cloud_print_after_order_details'], 10, 2);
  109. add_action('admin_print_footer_scripts', [$this, 'devvn_admin_print_footer_scripts'], 999999);
  110. add_action('wp_ajax_ghtk_tracking', [$this, 'ghtk_tracking_func']);
  111. add_action('wp_ajax_nopriv_ghtk_tracking', [$this, 'ghtk_tracking_func']);
  112. add_shortcode('ghtk_tracking_form', [$this, 'ghtk_tracking_form_func']);
  113. add_filter('woocommerce_formatted_address_replacements', [$this, 'devvn_woocommerce_formatted_address_replacements'], 9);
  114. add_action('devvn_ghtk_action', [$this, 'devvn_ghtk_action_func']);
  115. add_action('wp_ajax_ghtk_creat_order_ajax', [$this, 'ghtk_creat_order_ajax_func']);
  116. add_filter('bulk_actions-edit-shop_order', [$this, 'define_bulk_actions']);
  117. add_filter('handle_bulk_actions-edit-shop_order', [$this, 'ghtk_bulk_action_handler'], 10, 3);
  118. add_filter('woocommerce_customer_meta_fields', [$this, 'woocommerce_customer_meta_fields']);
  119. add_filter('woocommerce_general_settings', [$this, 'woocommerce_general_settings']);
  120. add_action('woocommerce_admin_field_selectajax', [$this, 'woocommerce_admin_field_selectajax']);
  121. add_action('woocommerce_my_account_my_orders_column_order-status', [$this, 'devvn_custom_order_status_myaccount']);
  122. add_action('woocommerce_checkout_update_order_review', [$this, 'devvn_update_checkout_func'], 10);
  123. include_once DEVVN_GHTK_PLUGIN_DIR . '/includes/freeshipping-by-payment-methob.php';
  124. $free_shipping = get_option('woocommerce_devvn_freeshipping_by_paymentmethod_settings');
  125. $this->enabled_free_shipping = (isset($free_shipping['enabled']) ? $free_shipping['enabled'] : 'no');
  126. }
  127.  
  128. public function get_ghtk_options()
  129. {
  130. return wp_parse_args(get_option($this->_optionName), $this->_defaultOptions);
  131. }
  132.  
  133. public function set_weight_option()
  134. {
  135. $wc_weight = get_option('woocommerce_weight_unit');
  136.  
  137. if ($wc_weight == 'g') {
  138. $this->_weight_option = 'gram';
  139. }
  140. }
  141.  
  142. static public function on_activation()
  143. {
  144. if (!current_user_can('activate_plugins')) {
  145. return false;
  146. }
  147.  
  148. $plugin = (isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '');
  149. check_admin_referer('activate-plugin_' . $plugin);
  150. }
  151.  
  152. static public function on_deactivation()
  153. {
  154. if (!current_user_can('activate_plugins')) {
  155. return false;
  156. }
  157.  
  158. $plugin = (isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '');
  159. check_admin_referer('deactivate-plugin_' . $plugin);
  160. }
  161.  
  162. static public function on_uninstall()
  163. {
  164. if (!current_user_can('activate_plugins')) {
  165. return false;
  166. }
  167. }
  168.  
  169. public function admin_menu()
  170. {
  171. add_submenu_page('woocommerce', __('Cài đặt GHTK', 'devvn-ghtk'), __('Cài đặt GHTK', 'devvn-ghtk'), 'manage_woocommerce', 'devvn-woo-ghtk', [$this, 'devvn_district_setting']);
  172. }
  173.  
  174. public function register_mysettings()
  175. {
  176. register_setting($this->_optionGroup, $this->_optionName);
  177. }
  178.  
  179. public function devvn_district_setting()
  180. {
  181. wp_enqueue_media();
  182. include 'includes/setting-page.php';
  183. }
  184.  
  185. public function vietnam_cities_woocommerce($states)
  186. {
  187. $states['VN'] = $this->get_tinhthanhpho();
  188. return $states;
  189. }
  190.  
  191. public function custom_override_checkout_fields($fields)
  192. {
  193. if ($this->get_options('enable_gender')) {
  194. $fields['billing']['billing_gender'] = [
  195. 'label' => __('Gender', 'devvn-ghtk'),
  196. 'priority' => 5,
  197. 'default' => 'female',
  198. 'required' => true,
  199. 'type' => 'radio',
  200. 'options' => ['male' => __('Mr', 'devvn-ghtk'), 'female' => __('Mrs', 'devvn-ghtk')]
  201. ];
  202. }
  203.  
  204. if (!$this->get_options('alepay_support')) {
  205. $fields['billing']['billing_first_name'] = [
  206. 'label' => __('Full name', 'devvn-ghtk'),
  207. 'placeholder' => _x('Type Full name', 'placeholder', 'devvn-ghtk'),
  208. 'required' => true,
  209. 'class' => ['form-row-wide'],
  210. 'clear' => true,
  211. 'priority' => 10
  212. ];
  213. }
  214.  
  215. if (isset($fields['billing']['billing_phone'])) {
  216. $fields['billing']['billing_phone']['class'] = ['form-row-first'];
  217. $fields['billing']['billing_phone']['placeholder'] = __('Type your phone', 'devvn-ghtk');
  218. }
  219.  
  220. if (isset($fields['billing']['billing_email'])) {
  221. $fields['billing']['billing_email']['class'] = ['form-row-last'];
  222. $fields['billing']['billing_email']['placeholder'] = __('Type your email', 'devvn-ghtk');
  223. }
  224.  
  225. $fields['billing']['billing_state'] = [
  226. 'label' => __('Province/City', 'devvn-ghtk'),
  227. 'required' => true,
  228. 'type' => 'select',
  229. 'class' => ['form-row-first', 'devvn-address-field'],
  230. 'placeholder' => _x('Select Province/City', 'placeholder', 'devvn-ghtk'),
  231. 'options' => ['' => __('Select Province/City', 'devvn-ghtk')] + $this->get_tinhthanhpho(),
  232. 'priority' => 30
  233. ];
  234. $fields['billing']['billing_city'] = [
  235. 'label' => __('District', 'devvn-ghtk'),
  236. 'required' => true,
  237. 'type' => 'select',
  238. 'class' => ['form-row-last', 'address-field', 'update_totals_on_change'],
  239. 'placeholder' => _x('Select District', 'placeholder', 'devvn-ghtk'),
  240. 'options' => ['' => ''],
  241. 'priority' => 40
  242. ];
  243.  
  244. if (!$this->get_options()) {
  245. $fields['billing']['billing_address_2'] = [
  246. 'label' => __('Commune/Ward/Town', 'devvn-ghtk'),
  247. 'required' => true,
  248. 'type' => 'select',
  249. 'class' => ['form-row-first', 'devvn-address-field'],
  250. 'placeholder' => _x('Select Commune/Ward/Town', 'placeholder', 'devvn-ghtk'),
  251. 'options' => ['' => ''],
  252. 'priority' => 50
  253. ];
  254.  
  255. if ($this->get_options('required_village')) {
  256. $fields['billing']['billing_address_2']['required'] = false;
  257. }
  258. }
  259.  
  260. $fields['billing']['billing_address_1']['placeholder'] = _x('Ex: No. 20, 90 Alley', 'placeholder', 'devvn-ghtk');
  261.  
  262. if (!$this->get_options()) {
  263. $fields['billing']['billing_address_1']['class'] = ['form-row-last'];
  264. }
  265. else {
  266. $fields['billing']['billing_address_1']['class'] = ['form-row-wide'];
  267. }
  268.  
  269. $fields['billing']['billing_address_1']['priority'] = 60;
  270.  
  271. if (isset($fields['billing']['billing_phone'])) {
  272. $fields['billing']['billing_phone']['priority'] = 20;
  273. }
  274.  
  275. if (isset($fields['billing']['billing_email'])) {
  276. $fields['billing']['billing_email']['priority'] = 21;
  277. }
  278.  
  279. if (!$this->get_options('alepay_support')) {
  280. unset($fields['billing']['billing_country']);
  281. unset($fields['billing']['billing_last_name']);
  282. }
  283. else {
  284. $fields['billing']['billing_country']['priority'] = 22;
  285. }
  286.  
  287. unset($fields['billing']['billing_company']);
  288.  
  289. if (!$this->get_options('alepay_support')) {
  290. $fields['shipping']['shipping_first_name'] = [
  291. 'label' => __('Full name', 'devvn-ghtk'),
  292. 'placeholder' => _x('Type Full name', 'placeholder', 'devvn-ghtk'),
  293. 'required' => true,
  294. 'class' => ['form-row-first'],
  295. 'clear' => true,
  296. 'priority' => 10
  297. ];
  298. }
  299.  
  300. $fields['shipping']['shipping_phone'] = [
  301. 'label' => __('Phone', 'devvn-ghtk'),
  302. 'placeholder' => _x('Phone', 'placeholder', 'devvn-ghtk'),
  303. 'required' => false,
  304. 'class' => ['form-row-last'],
  305. 'clear' => true,
  306. 'priority' => 20
  307. ];
  308.  
  309. if ($this->get_options('alepay_support')) {
  310. $fields['shipping']['shipping_phone']['class'] = ['form-row-wide'];
  311. }
  312.  
  313. $fields['shipping']['shipping_state'] = [
  314. 'label' => __('Province/City', 'devvn-ghtk'),
  315. 'required' => true,
  316. 'type' => 'select',
  317. 'class' => ['form-row-first', 'devvn-address-field'],
  318. 'placeholder' => _x('Select Province/City', 'placeholder', 'devvn-ghtk'),
  319. 'options' => ['' => __('Select Province/City', 'devvn-ghtk')] + $this->get_tinhthanhpho(),
  320. 'priority' => 30
  321. ];
  322. $fields['shipping']['shipping_city'] = [
  323. 'label' => __('District', 'devvn-ghtk'),
  324. 'required' => true,
  325. 'type' => 'select',
  326. 'class' => ['form-row-last', 'address-field', 'update_totals_on_change'],
  327. 'placeholder' => _x('Select District', 'placeholder', 'devvn-ghtk'),
  328. 'options' => ['' => ''],
  329. 'priority' => 40
  330. ];
  331.  
  332. if (!$this->get_options()) {
  333. $fields['shipping']['shipping_address_2'] = [
  334. 'label' => __('Commune/Ward/Town', 'devvn-ghtk'),
  335. 'required' => true,
  336. 'type' => 'select',
  337. 'class' => ['form-row-first', 'devvn-address-field'],
  338. 'placeholder' => _x('Select Commune/Ward/Town', 'placeholder', 'devvn-ghtk'),
  339. 'options' => ['' => ''],
  340. 'priority' => 50
  341. ];
  342.  
  343. if ($this->get_options('required_village')) {
  344. $fields['shipping']['shipping_address_2']['required'] = false;
  345. }
  346. }
  347.  
  348. $fields['shipping']['shipping_address_1']['placeholder'] = _x('Ex: No. 20, 90 Alley', 'placeholder', 'devvn-ghtk');
  349.  
  350. if (!$this->get_options()) {
  351. $fields['shipping']['shipping_address_1']['class'] = ['form-row-last'];
  352. }
  353. else {
  354. $fields['shipping']['shipping_address_1']['class'] = ['form-row-wide'];
  355. }
  356.  
  357. $fields['shipping']['shipping_address_1']['priority'] = 60;
  358.  
  359. if (!$this->get_options('alepay_support')) {
  360. unset($fields['shipping']['shipping_country']);
  361. unset($fields['shipping']['shipping_last_name']);
  362. }
  363. else {
  364. $fields['shipping']['shipping_country']['priority'] = 22;
  365. }
  366.  
  367. unset($fields['shipping']['shipping_company']);
  368. uasort($fields['billing'], [$this, 'sort_fields_by_order']);
  369. uasort($fields['shipping'], [$this, 'sort_fields_by_order']);
  370. return apply_filters('ghtk_custom_field_checkout', $fields);
  371. }
  372.  
  373. public function sort_fields_by_order($a, $b)
  374. {
  375. if (!isset($b['priority']) || !isset($a['priority']) || ($a['priority'] == $b['priority'])) {
  376. return 0;
  377. }
  378.  
  379. return $a['priority'] < $b['priority'] ? -1 : 1;
  380. }
  381.  
  382. public function search_in_array($array, $key, $value)
  383. {
  384. $results = [];
  385.  
  386. if (is_array($array)) {
  387. if (isset($array[$key]) && ($array[$key] == $value)) {
  388. $results[] = $array;
  389. }
  390. else if (isset($array[$key]) && is_serialized($array[$key]) && in_array($value, maybe_unserialize($array[$key]))) {
  391. $results[] = $array;
  392. }
  393.  
  394. foreach ($array as $subarray) {
  395. $results = array_merge($results, $this->search_in_array($subarray, $key, $value));
  396. }
  397. }
  398.  
  399. return $results;
  400. }
  401.  
  402. public function check_file_open_status($file_url = '')
  403. {
  404. if (!$file_url) {
  405. return false;
  406. }
  407.  
  408. try {
  409. $response = @file_get_contents($file_url);
  410. $status_line = $http_response_header[0];
  411. preg_match('{HTTP\\/\\S*\\s(\\d{3})}', $status_line, $match);
  412. $status = (isset($match[1]) ? $match[1] : false);
  413. return $status;
  414. }
  415. catch (Exception $e) {
  416. return false;
  417. }
  418.  
  419. return false;
  420. }
  421.  
  422. public function devvn_enqueue_UseAjaxInWp()
  423. {
  424. if (is_checkout() || is_page(get_option('woocommerce_edit_address_page_id'))) {
  425. wp_enqueue_style('ghtk_styles', plugins_url('/assets/css/devvn_dwas_style.css', __FILE__), [], $this->_version, 'all');
  426. wp_enqueue_script('devvn_tinhthanhpho', plugins_url('assets/js/devvn_tinhthanh.js', __FILE__), ['jquery', 'select2'], $this->_version, true);
  427. $get_address = DEVVN_GHTK_URL . 'get-address.php';
  428.  
  429. if ($this->check_file_open_status($get_address) != 200) {
  430. $get_address = admin_url('admin-ajax.php');
  431. }
  432.  
  433. $php_array = ['admin_ajax' => admin_url('admin-ajax.php'), 'get_address' => $get_address, 'home_url' => home_url(), 'formatNoMatches' => __('No value', 'devvn-ghtk'), 'enabled_free_shipping' => false];
  434.  
  435. if ($this->enabled_free_shipping == 'yes') {
  436. $php_array['enabled_free_shipping'] = true;
  437. }
  438.  
  439. wp_localize_script('devvn_tinhthanhpho', 'ghtk_array', $php_array);
  440. }
  441. }
  442.  
  443. public function load_diagioihanhchinh_func()
  444. {
  445. $matp = (isset($_POST['matp']) ? sanitize_text_field($_POST['matp']) : '');
  446. .............................................................................
  447. ................................................
  448. ........................
Add Comment
Please, Sign In to add comment