prefix ."woocommerce_custom_region_by_country";
$alert = "";
$noticetype = "";
if(isset($_POST['action']) && isset($_POST['action'])){
$post_action = sanitize_text_field($_POST['action']);
}
if (isset($post_action) && $post_action != "") {
if ($post_action == 'add_new_region') {
$cdate = date('Y-m-d H:i:s');
$country_code = sanitize_text_field($_POST['country_code']);
$region_list = sanitize_textarea_field($_POST['region_list']);
if ($wpdb->insert(
$tablename, array(
'countrycode' => $country_code,
'regionlist' => $region_list,
'created_date' => $cdate
)) == true) {
$alert .= "New Region List Added.";
} else {
$alert .= "ERROR: multiple Region entry not allowed for same country. Please Update existing Region list.";
$noticetype .= "notice-error";
}
}
if ($post_action == 'edit_region') {
$uid = intval($_POST['id']);
$region_list= sanitize_textarea_field($_POST['region_list']);
if($uid){
if ($wpdb->update(
$tablename, array(
'regionlist'=>$region_list,),
array('id' => $uid)) == true) {
$alert.="Region List Updated.";
}
} else {
$alert.="ERROR: Price List NOT Updated";
}
}
}
if(isset($_GET['action']) && isset($_GET['action']) || isset($_GET['uid']) && isset($_GET['uid'])){
$get_action = sanitize_text_field($_GET['action']);
$get_uid = sanitize_text_field($_GET['uid']);
}
if (isset($get_action) && isset($get_uid) && ($get_action=='update')) {
$uid = $get_uid;
region_build_form('edit-map', $uid,$alert);
} else {
$uid='';
region_build_form('add-map', $uid,$alert);
}
function region_build_form($type, $id,$alert){
if ($type == 'add-map') {
$message = "Add the details of Region.";
$formname = "add_new_region";
$title = " Add Region";
$location = "";
$room_category = "";
$price="";
$price_dollar = "";
$custom_action = '';
$submit_action = "add_new_region";
$submit_bt_value = "Add Region";
$countrycode='';
$allowedit = '';
$dbid = '';
$noticetype= '';
}
if($type == 'edit-map') {
global $wpdb;
$tablename=$wpdb->prefix ."woocommerce_custom_region_by_country";
$region_dbdata = $wpdb->get_row("SELECT * FROM $tablename WHERE id = '$id'", ARRAY_A);
$title = "Update Region";
$message = "You can edit your Region from here.";
$formname = "edit_region";
$dbid = $region_dbdata['id'];
$countrycode = $region_dbdata['countrycode'];
$regionlist = $region_dbdata['regionlist'];
$submit_action = "edit_region";
$submit_bt_value = "Update Region";
$allowedit = 'disabled readonly';
$noticetype ='';
}
?>
' . __( 'Success! This Regions deleted Successfully.', 'cmetric-arbyw' ). '
';
}
?>