-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwshop-meta.php
41 lines (37 loc) · 1.49 KB
/
wshop-meta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/*
* Add custom metabox to the new/edit page
*/
function wshop_add_page_metaboxes(){
add_meta_box('wshop_product_meta', 'Product Meta', 'wshop_product_meta', 'wps-product', 'normal', 'low');
}
add_action('add_meta_boxes', 'wshop_add_page_metaboxes');
// add meta box to pages
function wshop_product_meta() {
global $post;
?>
<div class="custom-meta">
<label for="product-id">Product ID:</label>
<input disabled id="product-id" class="short" title="This is needed for all product pages" name="_wshop_product_id" type="text" value="<?php echo $post->_wshop_product_id; ?>">
<br/>
<label for="link-url">Enter The Product Vendor:</label>
<input id="link-url" class="long" name="_custom_product_vendor" type="text" value="<?php echo $post->_custom_product_vendor; ?>">
</div>
<?php
}
/*
* Save the metabox vaule
*/
function wshop_save_metabox($post_id){
// check autosave
if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
if( isset($_POST['_wshop_product_id']) ) {
update_post_meta($post_id, '_wshop_product_id', $_POST['_wshop_product_id']);
}
if( isset($_POST["_custom_product_vendor"]) ) {
update_post_meta($post_id, "_custom_product_vendor", trim($_POST["_custom_product_vendor"]));
}
}
add_action('save_post', 'wshop_save_metabox');