function edit_product()
{
    global $wpdb;
    $wpmp_obj3 = new MP_Form_Handler();
    global $mp_obj;
    $wc_currency = get_woocommerce_currency_symbol(get_option('woocommerce_currency'));
    $user_id = get_current_user_id();
    if (isset($_GET['pid'])) {
        $post_id = $wk_pro_id = $_GET['pid'];
        if ($_POST) {
            if (isset($_POST['add_product_sub'])) {
                /*MP_Form_Handler::product_add_update();*/
                $wpmp_obj3->product_add_update();
            }
        }
    } else {
        if (isset($_POST['add_product_sub'])) {
            /*$wk_pro_p=MP_Form_Handler::product_add_update();*/
            $wk_pro_p = $wpmp_obj3->product_add_update();
            $wk_pro_id = $wk_pro_p[0];
        }
    }
    /*MP_Form_Handler::marketplace_media_fix($post_id);*/
    $wpmp_obj3->marketplace_media_fix();
    $product_auth = $wpdb->get_var("select post_author from {$wpdb->posts} where ID='" . $wk_pro_id . "'");
    if (isset($wk_pro_id) && $product_auth == $user_id) {
        $post_row_data = $wpdb->get_results("select * from {$wpdb->posts} where ID=" . $wk_pro_id);
        $postmeta_row_data = get_post_meta($wk_pro_id);
        /*$product_images= MP_Form_Handler::get_product_image($wk_pro_id,'_thumbnail_id');*/
        $product_images = $wpmp_obj3->get_product_image($wk_pro_id, '_thumbnail_id');
        $meta_arr = array();
        foreach ($postmeta_row_data as $key => $value) {
            $meta_arr[$key] = $value[0];
        }
        $product_attributes = get_post_meta($wk_pro_id, '_product_attributes', true);
        $display_variation = 'no';
        if (!empty($product_attributes)) {
            foreach ($product_attributes as $variation) {
                if ($variation['is_variation'] == 1) {
                    $display_variation = 'yes';
                }
            }
        }
        /*$image_gallary=MP_Form_Handler::get_product_image($wk_pro_id,'_product_image_gallery');*/
        $image_gallary = $wpmp_obj3->get_product_image($wk_pro_id, '_product_image_gallery');
    }
    ?>


<h2><?php 
    echo _e("Edit Product");
    ?>
</h2>
<input type="hidden" name="var_variation_display" id="var_variation_display" value="<?php 
    echo $display_variation;
    ?>
" />

<ul id='edit_product_tab'>

    <li><a id='edit_tab'><?php 
    echo _e("Edit");
    ?>
</a></li>

   <li><a id='inventorytab'><?php 
    echo _e("Inventory");
    ?>
</a></li>


    <li><a id='attributestab'><?php 
    echo _e("Attributes");
    ?>
</a></li>


    <li style="display:none;"><a id='avariationtab'><?php 
    echo _e("Variations");
    ?>
</a></li>


	<li><a id='pro_statustab'><?php 
    echo _e("Product Status");
    ?>
</a></li>


 </ul>


	<form action="" method="post" enctype="multipart/form-data" id="product-form">


 <div class="wk_mp_container form" id="edit_tabwk">	
 		<table>


			<tbody>			

			<div class="product-type mp-toggle-sidebar">

							<label for="product_type">Product Type:</label>


							<!-- <span class="mp-toggle-type-display"><?php 
    if (isset($meta_arr['_simple']) && $meta_arr['_simple'] == 'yes') {
        echo 'Simple Product';
    }
    if ($meta_arr['_downloadable'] == 'yes') {
        echo 'Downloadable Product';
    }
    if ($meta_arr['_virtual'] == 'yes') {
        echo 'Virtual Product';
    }
    ?>
</span> -->


							<!-- <a class="mp-product-toggle-edit label label-success" href="javascript:void(0);">Edit</a>


							<div class="mp-toggle-select-type-container mp-hide" style="display:none;"> -->



							<select name="product_type" id="product_type" class="mp-toggle-select">


								<?php 
    $mp_product_type = $wpdb->get_results("select term.term_id,term.name from {$wpdb->prefix}terms as term join  {$wpdb->prefix}term_taxonomy as wtt on wtt.term_id=term.term_id where wtt.taxonomy='product_type'");
    $pro_term_relation = $wpdb->get_var("select wtr.term_taxonomy_id from {$wpdb->prefix}term_relationships as wtr join {$wpdb->prefix}term_taxonomy wtt on  wtr.term_taxonomy_id=wtt.term_taxonomy_id where wtt.taxonomy='product_type' and wtr.object_id={$wk_pro_id}");
    foreach ($mp_product_type as $pro_type) {
        if ($pro_type->name == 'external') {
            continue;
        }
        if ($pro_type->name == 'grouped') {
            continue;
        }
        ?>
									<option value="<?php 
        echo $pro_type->name;
        ?>
" <?php 
        if ($pro_type->term_id == $pro_term_relation) {
            echo 'selected="selected"';
        }
        ?>
 ><?php 
        echo $pro_type->name;
        ?>
</option>

								<?php 
    }
    ?>

							</select>

							<!-- <a class="mp-toggle-type-save btn btn-default btn-sm" href="javascript:void(0);">OK</a>


							<a class="mp-toggle-type-cancel btn" href="javascript:void(0);">Cancel</a>


							</div>
 -->

						</div>

				<tr>


					<td><label for="product_name"><?php 
    echo _e("Product Name");
    ?>
<span class="required">*</span>&nbsp;&nbsp;:</label></td>


					<td><input class="product_input" type="text" name="product_name" id="product_name" size="54" value="<?php 
    if (isset($post_row_data[0]->post_title)) {
        echo $post_row_data[0]->post_title;
    }
    ?>
" />


					<div id="pro_name_error" class="error-class"></div>


					</td>


				</tr>


				<tr style="display:none;">


						<td>


						<?php 
    if (isset($wk_pro_id) && isset($_GET['page']) && $_GET['page'] == 'eProduct') {
        ?>


						<input type="hidden" value="<?php 
        echo $wk_pro_id;
        ?>
" name="sell_pr_id" id="sell_pr_id" />


						<?php 
    }
    ?>


						<td>


				</tr>


				<tr>


						<td><label for="product_desc"><?php 
    echo _e("About Product");
    ?>
&nbsp;&nbsp;:</label></td>


						<td><?php 
    $settings = array('media_buttons' => true, 'textarea_name' => 'product_desc', 'textarea_rows' => get_option('default_post_edit_rows', 10), 'tabindex' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => false);
    if (isset($post_row_data[0]->post_content)) {
        $content = $post_row_data[0]->post_content;
    }
    if (isset($content)) {
        echo wp_editor("{$content}", 'product_desc', $settings);
    } else {
        echo wp_editor("", 'product_desc', $settings);
    }
    ?>


						<div id="long_desc_error" class="error-class"></div>


						</td>


				</tr>                   


				<tr>					


					<td><label for="product_category"><?php 
    echo _e("Product Category");
    ?>
&nbsp;&nbsp;:</label></td>


					<td>


					<select multiple="true" name="product_cate[]" id="product_cate">


					<?php 
    /*MP_Form_Handler::mp_product_categories1(0,$wk_pro_id);*/
    ?>
					<?php 
    $wpmp_obj3->mp_product_categories1(0, $wk_pro_id);
    ?>


					</select>


					</td>


				</tr>


				<tr>


					<td><label for="fileUpload"><?php 
    echo _e("Product Thumbnail");
    ?>
&nbsp;&nbsp;:</label></td>


					<td><?php 
    if (isset($meta_arr['image'])) {
        ?>


					<img src="" width="50" height="50">


					<?php 
    }
    ?>


					<div id="product_image">


					</div>


					<input type="hidden"  id="product_thumb_image_mp" name="product_thumb_image_mp" value="<?php 
    if (isset($meta_arr['_thumbnail_id'])) {
        echo $meta_arr['_thumbnail_id'];
    }
    ?>
" />

									
					<a class="upload mp_product_thumb_image btn" href="javascript:void(0);" /><?php 
    _e('Upload Thumb');
    ?>
</a>

					
					<?php 
    if (!empty($product_images)) {
        echo "<img style='display:inline;' src='" . content_url() . "/uploads/" . $product_images . "' width=50 height=50 />";
    }
    ?>


					</td>


				</tr>


				<tr>
					 <!-- <td><label for="product_sku"><?php 
    /*echo _e("Product SKU");*/
    ?>
<span class="required">*</span>&nbsp;&nbsp;:</label></td> -->
					<td>
					 	<label for="product_sku"><?php 
    echo _e("Product SKU");
    ?>
                        		<span class="required">*</span>: &nbsp;
                        		<span class="help">
	                        		<div class="help-tip-sol"><?php 
    echo _e("SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.");
    ?>
	                        		</div>
                        			<span class="help-tip">[?]</span>
                        		</span>
                        	</label>
					</td>


					 <td><input class="product_input" type="text" name="product_sku" id="product_sku" value="<?php 
    if (isset($meta_arr['_sku'])) {
        echo $meta_arr['_sku'];
    }
    ?>
" />


					 <div id="pro_sku_error" class="error-class"></div></td>


				 </tr>

				 <?php 
    /*if($pro_term_relation[0]->term_taxonomy_id!=4){*/
    ?>
				 <tr id="regularPrice">


					 <td><label for="regu_price"><?php 
    echo _e("Regular Price");
    ?>
<span class="required">*</span>&nbsp;&nbsp;:</label></td>


					 <td><input class="product_input" type="text" name="regu_price" id="regu_price" value="<?php 
    if (isset($meta_arr['_regular_price'])) {
        echo $meta_arr['_regular_price'];
    }
    ?>
" <?php 
    echo $pro_term_relation == 4 ? 'disabled' : '';
    ?>
/>


					  <div id="regl_pr_error" class="error-class"></div></td>


				 </tr>


				<tr id="salePrice">


					<td>
						<label for="sale_price"><?php 
    echo _e("Sale Price");
    ?>
&nbsp;&nbsp;:</label>
					</td>


					 <td><input class="product_input" type="text" name="sale_price" id="sale_price" value="<?php 
    if (isset($meta_arr['_sale_price'])) {
        echo $meta_arr['_sale_price'];
    }
    ?>
" <?php 
    echo $pro_term_relation == 4 ? 'disabled' : '';
    ?>
/>


					<div id="sale_pr_error" class="error-class"></div></td>

				 </tr>
				 <?php 
    /*}*/
    ?>


				 <tr>


						<td><label for="short_desc"><?php 
    echo _e("Product Short Desc");
    ?>
&nbsp;&nbsp;:</label></td>


						 <td><?php 
    $settings = array('media_buttons' => true, 'textarea_name' => 'short_desc', 'textarea_rows' => get_option('default_post_edit_rows', 10), 'tabindex' => '', 'editor_class' => 'backend', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => false, 'drag_drop_upload' => true);
    if (isset($post_row_data[0]->post_excerpt)) {
        $short_content = $post_row_data[0]->post_excerpt;
    }
    if (isset($short_content)) {
        echo wp_editor("{$short_content}", 'short_desc', $settings);
    } else {
        echo wp_editor("", 'short_desc', $settings);
    }
    ?>


						<div id="short_desc_error" class="error-class"></div></td>                       


				</tr>


				</tbody>


				</table>


		  </div>


       <div class="wk_mp_container" id="inventorytabwk">


				<table>


				<tbody>


				<tr>            


				  <td>


				  	  <label for="wk-mp-stock"><?php 
    echo _e("Manage Stock?");
    ?>
&nbsp;:</label></td>


                        <td>
                        <label for="wk_stock_management" style="width: 100%;">
                        	<input type="checkbox" class="wk_stock_management" id="wk_stock_management" name="wk_stock_management" value ="yes" <?php 
    if (isset($meta_arr['_manage_stock']) && $meta_arr['_manage_stock'] == 'yes') {
        echo "checked";
    }
    ?>
 /><?php 
    _e("Enable stock management at product level");
    ?>
                        </label>


						</td>


                    </tr>


					<tr>


                        <td><label for="wk-mp-stock"><?php 
    echo _e("Stock Qty");
    ?>
&nbsp;:</label></td>


                        <td><input type="text" class="product_input" placeholder="0" name="wk-mp-stock-qty" id="wk-mp-stock-qty" value="<?php 
    echo isset($meta_arr['_stock']) ? $meta_arr['_stock'] : '';
    ?>
" /></td>


                    </tr>	


					<tr>


                        <td><label for="wk-mp-stock"><?php 
    echo _e("Stock Status");
    ?>
&nbsp;:</label></td>


                        <td>


						<select name="_stock_status" id="_stock_status" class="form-control">						


							<option value="instock" <?php 
    if (isset($meta_arr['_stock_status']) && $meta_arr['_stock_status'] == 'instock') {
        echo 'selected="selected"';
    }
    ?>
 ><?php 
    _e("In Stock");
    ?>
</option>


							<option value="outofstock" <?php 
    if (isset($meta_arr['_stock_status']) && $meta_arr['_stock_status'] == 'outofstock') {
        echo 'selected="selected"';
    }
    ?>
><?php 
    _e("Out of Stock");
    ?>
</option>


						</select>


						</td>


                    </tr>


					<tr>


                        <td><label for="wk-mp-backorders"><?php 
    echo _e("Allow Backorders");
    ?>
&nbsp;:</label></td>


                        <td>


							<select name="_backorders" id="_backorders" class="form-control">


							<option value="no" <?php 
    if (isset($meta_arr['_backorders']) && $meta_arr['_backorders'] == 'no') {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo _e("Do not allow");
    ?>
</option>


							<option value="notify" <?php 
    if (isset($meta_arr['_backorders']) && $meta_arr['_backorders'] == 'notify') {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo _e("Allow but notify customer");
    ?>
</option>


							<option value="yes" <?php 
    if (isset($meta_arr['_backorders']) && $meta_arr['_backorders'] == 'yes') {
        echo 'selected="selected"';
    }
    ?>
><?php 
    _e("Allow");
    ?>
</option>


							</select>	


						</td>


                    </tr>	


					


					


				</tbody>


				</table>


		  </div>


          <div class="wk_mp_container" id="attributestabwk">


		   <div class="input_fields_toolbar">


		<button class="btn btn-success add-variant-attribute"><?php 
    _e("+ Add an attribute");
    ?>
</button>


		<!--<button type="button" class="btn btn-default save_attributes" data-id="1347"><?php 
    echo _e("Save attributes");
    ?>
</button> -->


		</div>


			<div  class="wk_marketplace_attributes">
			<?php 
    if (!empty($product_attributes)) {
        $i = 0;
        foreach ($product_attributes as $proatt) {
            ?>
			<div class="wk_mp_attributes">
				<div class="box-header attribute-remove">
				<input type="text" class="mp-attributes-name" placeholder="Attribute name" name="pro_att[<?php 
            echo $i;
            ?>
][name]" value="<?php 
            echo str_replace('-', ' ', $proatt['name']);
            ?>
"/><input type="text" class="option" title="attribue value by seprating comma eg. a|b|c" placeholder=" Value eg. a|b|c" name="pro_att[<?php 
            echo $i;
            ?>
][value]" value="<?php 
            echo $proatt['value'];
            ?>
"/>
				<input type="hidden" name="pro_att[<?php 
            echo $i;
            ?>
][position]" class="attribute_position" value="<?php 
            echo $proatt['position'];
            ?>
"/>


						<span class="mp_actions">


							<button class="mp_attribute_remove btn btn-danger">Remove</button>


						</span>


					</div>


					<div class="box-inside clearfix">


						<div class="wk-mp-attribute-config">


							<div class="checkbox-inline">


								<input id="wkmp_check1_<?php 
            echo $i;
            ?>
" type="checkbox" class="checkbox" name="pro_att[<?php 
            echo $i;
            ?>
][is_visible]" value="1" <?php 
            if ($proatt['is_visible'] == '1') {
                echo "checked";
            }
            ?>
/><label for="wkmp_check1_<?php 
            echo $i;
            ?>
" style="width: 185px;">Visible on the product page</label></div>


							<div class="checkbox-inline">


								<input id="product_att_varitioN_<?php 
            echo $i;
            ?>
" type="checkbox" class="checkbox" name="pro_att[<?php 
            echo $i;
            ?>
][is_variation]" value="1" <?php 
            if ($proatt['is_variation'] == '1') {
                echo "checked";
            }
            ?>
/><label for="product_att_varitioN_<?php 
            echo $i;
            ?>
">Used for variations</label>


							</div>


							<input type="hidden" name="pro_att[<?php 
            echo $i;
            ?>
][is_taxonomy]" value="<?php 
            echo $proatt['taxonomy'];
            ?>
"/>


						</div>


						<div class="attribute-options"></div>


					</div>


				</div>


				<?php 
            $i++;
        }
    }
    ?>


			</div>

	  </div>
<!-- varication attribute of the product -->
	 <div class="wk_mp_container" id="avariationtabwk">
		<div id="mp_attribute_variations">
		<?php 
    echo $mp_obj->marketplace_attributes_variation($wk_pro_id);
    ?>
		 </div>
		 <div class="input_fields_toolbar_variation">
			<button id="mp_var_attribute_call" class="btn btn-success "><?php 
    _e("+ Add Variation");
    ?>
</button>
			<input type="hidden" id="new_added_variation" name="new_added_variation" value="0">
		</div>

 	 </div>


	  <div class="wk_mp_container" id="pro_statustabwk">


	 			 	 <?php 
    if (get_option('wkmp_seller_allow_publish')) {
        ?>
	 			 	 <div class="mp-sidebar-container">


					<div class="mp_wk-post-status mp-toggle-sidebar">


						<label for="post_status"><?php 
        echo _e("Product Status:");
        ?>
</label>


						<span class="mp-toggle-selected-display"><?php 
        if (isset($post_row_data[0]->post_status) && !empty($post_row_data[0]->post_status) && $post_row_data[0]->post_status == 'publish') {
            echo 'Online';
        } else {
            echo 'draft';
        }
        ?>
 </span>


						<a class="mp-toggle-sider-edit label label-success" href="javascript:void(0);" style="display: inline;">Edit</a>


						


							<div class="mp-toggle-select-container mp-hide" style="display: none;">


								<select id="product_post_status" class="mp-toggle-select" name="mp_product_status">


								<option value="">Select status</option>

								<option value="publish" <?php 
        if ($post_row_data[0]->post_status == 'publish') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo _e("Online");
        ?>
</option>

								<option value="draft"  <?php 
        if ($post_row_data[0]->post_status == 'draft') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo _e("Draft");
        ?>
</option>


								</select>


								<a class="mp-toggle-save btn btn-default btn-sm" href="javascript:void(0);">OK</a>


								<a class="mp-toggle-cancel btn" href="javascript:void(0);">Cancel</a>


							</div>


						</div> 


						


						</div>
						<?php 
    }
    ?>

				


						<div class="wk-mp-side-head">


							<label class="checkbox-inline">


							<input type="checkbox" id="_ckdownloadable" name="_ckdownloadable" value="yes" <?php 
    if (isset($meta_arr['_downloadable']) && $meta_arr['_downloadable'] == 'yes') {
        echo 'checked';
    }
    ?>
/>&nbsp;<?php 
    _e("Downloadable Product", "marketplace");
    ?>
</label>


						</div>


						


						<div class="wk-mp-side-body" style="display:<?php 
    if (isset($meta_arr['_downloadable']) && $meta_arr['_downloadable'] == 'yes') {
        echo 'block';
    } else {
        echo 'none';
    }
    ?>
" >
						<?php 
    $mp_dwonloadable_file = get_post_meta($wk_pro_id, '_downloadable_files', true);
    $mp_download = array();
    if (!empty($mp_dwonloadable_file)) {
        foreach ($mp_dwonloadable_file as $key => $value) {
            $mp_download[] = $value;
        }
    }
    ?>

						<ul class="list-unstyled " style="list-style:none;">


						<li class="form-group">


						<table class="table table-condensed">


						<tr>


						<td>


						<p>


						<label><?php 
    echo _e('File Name:', 'marketplace');
    ?>
					


						</label>


						<input type="text" class="input_text" placeholder="File Name" id='user_downloadable_file_name' name="user_downloadable_file_name" value="<?php 
    if (isset($mp_download[0]['name'])) {
        echo $mp_download[0]['name'];
    }
    ?>
"/>


						</p>


						<p>


						<label><?php 
    echo _e('File URL :', 'marketplace');
    ?>
</label>
						
						<input type="text" class="input" placeholder="http://" id="upload_downloadable_file_url" name="upload_downloadable_file_url" value="<?php 
    if (isset($mp_download[0]['file'])) {
        echo $mp_download[0]['file'];
    }
    ?>
"/>


						</p>


						<p>


						<!-- <input type="file" class="upload_downloadable_file_type" name="wk_mp_product_downloadable" style="display:none" /> -->


						<a href="javascript:void(0);" class="btn btn-sm btn-default upload_file_button upload_downloadable_file">Choose file</a>


						<a href="#" class="btn btn-sm btn-danger delete">


						<span>Delete</span>


						</a>


						</p>


						</td>


						</tr>


						</tbody>


						</table>


						</li>


						<li class="form-group">


						<div class="input-group">


						<span class="input-group-addon">Limit</span>


						<input type="text" name="_download_limit" id="_download_limit" value="<?php 
    if (isset($meta_arr['_download_limit'])) {
        echo $meta_arr['_download_limit'];
    }
    ?>
" class="form-control" placeholder="Download Limit. e.g: 4"/>


						</div>


						</li>


						<li>


						<div class="input-group">


						<span class="input-group-addon">Expiry</span>


						<input type="text" name="_download_expiry" id="_download_expiry" value="<?php 
    if (isset($meta_arr['_download_expiry'])) {
        echo $meta_arr['_download_expiry'];
    }
    ?>
" class="form-control" placeholder="Number of days"/>


						</div>


						</li>


						</ul>


						</div>


							<div class="wk-mp-side-head">Image Gallery</div>


								<div id="wk-mp-product-images">


								<div id="product_images_container">


								<?php 
    if (isset($meta_arr['_product_image_gallery']) && $meta_arr['_product_image_gallery'] != '') {
        $image_id = explode(',', get_post_meta($wk_pro_id, '_product_image_gallery', true));
        for ($i = 0; $i < count($image_id); $i++) {
            $image_url = wp_get_attachment_image_src($image_id[$i]);
            echo "<div class='pro_image_gallary'><img src='" . $image_url[0] . "' width=50 height=50 />";
            ?>


							<ul class="actions" style="list-style:none;">


								<li>


								<a href="javascript:void(0);" id="<?php 
            echo $wk_pro_id . 'i_' . $image_id[$i];
            ?>
" class="mp-img-delete_gal" title="Delete image">Delete</a>


								</li>


								</ul>


								</div>


						<?php 
        }
    }
    ?>


								</div>


								<div id="handleFileSelectgalaray">


								</div>


								<input type="hidden" class="product_input" name="product_image_Galary_ids" id="product_image_Galary_ids" value="<?php 
    if (isset($meta_arr['_product_image_gallery'])) {
        echo $meta_arr['_product_image_gallery'];
    }
    ?>
" />


								</div>


								<a href="javascript:void(0);" class="add-mp-product-images btn">+ Add product images</a>


					 </p> 


					 <?php 
    wp_nonce_field('marketplace-edid_product');
    ?>


					 </div>


		


		<input type="submit" name="add_product_sub" id="add_product_sub" value="Update" class="button"/></td>


		


       	</form>


				


<?php 
    unset($_POST);
}