unlinkFiles(); } else { $json_txt = file_get_contents(plugin_dir_path(ADE_CUSTOM_PLGUN_FILE) . 'inc/all_cities.txt'); $json_txt_gh = file_get_contents(plugin_dir_path(ADE_CUSTOM_PLGUN_FILE) . 'inc/all_cities_gh.txt'); if (get_option("ade_custom_ng") == false) { add_option('ade_custom_ng', $json_txt, '', 'yes'); add_option('ade_custom_gh', $json_txt_gh, '', 'yes'); //RMFIle new RMFile(); } } } public static function rm_database() { delete_option('ade_custom_ng'); delete_option('ade_custom_gh'); delete_option('ade_custom_time'); } public static function ade_custom_shipping($states) { $map = array(); foreach (self::$json as $city) { $ade_state_reference = get_option("ade_state_reference"); if ($ade_state_reference) { $ade_state_reference = unserialize($ade_state_reference); if (is_array($ade_state_reference)) { $is_active = $ade_state_reference["ade_state_reference"]; $data_array = $ade_state_reference["ade_lgas_state_reference"]; if ($is_active == "1") { if (in_array($city->state, $data_array)) { //skip continue; } } } } for ($i = 0; $i < count($city->lgas); $i++) { $map[$city->lgas[$i] . ', ' . $city->state] = $city->lgas[$i] . ', ' . $city->state; } } $states['NG'] = $map; return $states; } public static function ade_custom_shipping_gh($states) { $map = array(); foreach (self::$json_gh as $city) { if (count($city->lgas) == 0) { // $map[strtolower(str_replace(" ", "", $city->region))] = $city->region; $map[$city->region] = $city->region; } else { for ($i = 0; $i < count($city->lgas); $i++) { // $map[strtolower(str_replace(" ", "", $city->lgas[$i].$i.$i))] = $city->lgas[$i] . ', '.$city->state. ', '.$city->region; $map[$city->lgas[$i] . ', ' . $city->state . ', ' . $city->region] = $city->lgas[$i] . ', ' . $city->state . ', ' . $city->region; } } } $states['GH'] = $map; return $states; } /** * General City Setup */ public static function ade_custom_shipping_general($states) { try { //skip NG and GH if (array_key_exists("NG", $states)) { //return $states return $states; } if (array_key_exists("GH", $states)) { //return $states return $states; } //check if ade_custom_shipping_general is set in option $ade_custom_shipping_general = get_option("ade_custom_shipping_general", []); if (empty($ade_custom_shipping_general)) { return $states; } $ade_custom_shipping_general = unserialize($ade_custom_shipping_general); if (empty($ade_custom_shipping_general)) { return $states; } //loop through foreach ($ade_custom_shipping_general as $key => $value) { $states[$key] = $value; } return $states; } catch (\Exception $e) { error_log($e->getMessage()); return $states; } } public static function wcsettingsarea($settings) { $key = 0; foreach ($settings as $values) { $new_settings[$key] = $values; $key++; // Inserting array just after the post code in "Store Address" section if ($values['id'] == 'woocommerce_store_postcode') { $new_settings[$key] = array( 'title' => __('Ade State Splitting', 'ade-custom-shipping'), 'desc' => __('Enable', 'ade-custom-shipping'), 'id' => 'ade_state_spliting', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => __('Enable Ade Custom Shipping State Splitting, works only for Nigeria'), ); $key++; } } return $new_settings; } }