Add the following code in your function.php file or your plugin file
<?php
add_action('add_meta_boxes', function(){ add_meta_box('jamunaoil_metabox_hover', 'Upload Product Icon Hover','jamunaoil_product_icon_hover', 'product','side', 'low'); }, 9);
function jamunaoil_product_icon_hover($post){
$url =get_post_meta($post->ID,'_jamunaoil_product_icon_hover', true);
?>
<img src="<?php echo $url;?>" style="width:200px;" id="jamunaoil_product_icon_hover_img" />
<input id="jamunaoil_product_icon_hover_url" name="jamunaoil_product_icon_hover_url" type="text" value="<?php echo $url;?>" style="width:100%;" />
<input id="jamunaoil_product_icon_hover_button" type="button" value="Upload Image" />
<script>
jQuery(document).ready( function( $ ) {
jQuery('#jamunaoil_product_icon_hover_button').click(function() {
window.send_to_editor = function(html) {
imgurl = jQuery(html).attr('src')
jQuery('#jamunaoil_product_icon_hover_url').val(imgurl);
jQuery('#jamunaoil_product_icon_hover_img').attr("src",imgurl);
tb_remove();
}
formfield = jQuery('#jamunaoil_product_icon_hover_url').attr('name');
tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );
return false;
});
});
</script>
<?php
}
add_action( 'save_post', function ($post_id) {
if (isset($_POST['jamunaoil_product_icon_hover_url'])){
update_post_meta($post_id, '_jamunaoil_product_icon_hover',$_POST['jamunaoil_product_icon_hover_url']);
}
});
?>
<?php
add_action('add_meta_boxes', function(){ add_meta_box('jamunaoil_metabox_hover', 'Upload Product Icon Hover','jamunaoil_product_icon_hover', 'product','side', 'low'); }, 9);
function jamunaoil_product_icon_hover($post){
$url =get_post_meta($post->ID,'_jamunaoil_product_icon_hover', true);
?>
<img src="<?php echo $url;?>" style="width:200px;" id="jamunaoil_product_icon_hover_img" />
<input id="jamunaoil_product_icon_hover_url" name="jamunaoil_product_icon_hover_url" type="text" value="<?php echo $url;?>" style="width:100%;" />
<input id="jamunaoil_product_icon_hover_button" type="button" value="Upload Image" />
<script>
jQuery(document).ready( function( $ ) {
jQuery('#jamunaoil_product_icon_hover_button').click(function() {
window.send_to_editor = function(html) {
imgurl = jQuery(html).attr('src')
jQuery('#jamunaoil_product_icon_hover_url').val(imgurl);
jQuery('#jamunaoil_product_icon_hover_img').attr("src",imgurl);
tb_remove();
}
formfield = jQuery('#jamunaoil_product_icon_hover_url').attr('name');
tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );
return false;
});
});
</script>
<?php
}
add_action( 'save_post', function ($post_id) {
if (isset($_POST['jamunaoil_product_icon_hover_url'])){
update_post_meta($post_id, '_jamunaoil_product_icon_hover',$_POST['jamunaoil_product_icon_hover_url']);
}
});
?>