Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. function create_product()
  2. {
  3. $labels = array(
  4. 'name' => _x( 'Product', 'post type general name', 'stacy' ),
  5. 'singular_name' => _x( 'product', 'post type singular name', 'stacy' ),
  6. 'menu_name' => _x( 'Products', 'admin menu', 'stacy' ),
  7. 'name_admin_bar' => _x( 'Product', 'add new on admin bar', 'stacy' ),
  8. 'add_new' => _x( 'Add New', 'product', 'stacy' ),
  9. 'add_new_item' => __( 'Add New Product', 'stacy' ),
  10. 'new_item' => __( 'New Product', 'stacy' ),
  11. 'edit_item' => __( 'Edit Product', 'stacy' ),
  12. 'view_item' => __( 'View Product', 'stacy' ),
  13. 'all_items' => __( 'All Product', 'stacy' ),
  14. 'search_items' => __( 'Search Product', 'stacy' ),
  15. 'not_found' => __( 'No Product found.', 'stacy' ),
  16. 'not_found_in_trash' => __( 'No Product found in Trash.', 'stacy' )
  17. );
  18. $args = array(
  19. 'labels' => $labels,
  20. 'description' => __( 'Description.', 'Add New Product on stacy' ),
  21. 'public' => true,
  22. 'publicly_queryable' => true,
  23. 'show_ui' => true,
  24. 'show_in_menu' => true,
  25. 'query_var' => true,
  26. 'rewrite' => array( 'slug' => 'product' ),
  27. 'has_archive' => true,
  28. 'hierarchical' => false,
  29. 'menu_position' => 100,
  30. 'menu_icon' =>'dashicons-cart',
  31. 'supports' => array( 'title', 'editor', 'author', 'thumbnail','comments','capabilities' ),
  32. 'taxonomies' => array('product_category','product_tag')
  33. );
  34. register_post_type( 'product', $args );
  35. }
  36. add_action( 'init', 'create_product' );
  37.  
  38. function add_product_details_meta_box()
  39. {
  40. global $wpdb;
  41. global $post;
  42. $custom = get_post_custom( $post->ID );
  43. <p>
  44. <label>Short Description:</label><br />
  45. <textarea rows="5" name="short_description" class="width99"><?= @$custom["short_description"][0] ?></textarea>
  46. </p>
  47. <p>
  48. <label>Price:</label><br />
  49. <input type="text" name="price" value="<?= @$custom["price"][0] ?>" class="width99" />
  50. </p>
  51.  
  52. <p>
  53. <label>Dimensions (in):</label><br />
  54. <input type="text" name="length" value="<?= @$custom["length"][0] ?>" class="s" placeholder="Length"/>
  55. </p>
  56. <p>
  57. <label>Shipping Lead Days:</label><br />
  58. <input type="text" name="ship_lead_days" value="<?= @$custom["product_ship_lead_days"][0] ?>" class="s" placeholder="Shipping Lead Days"/>
  59. </p>
  60. <p>
  61. <label>Commision:</label><br />
  62. <input type="text" name="commision_broker" value="<?= @$custom["commision_broker"][0] ?>" class="s" placeholder="Enter Your Commision Here"/>
  63. </p>
  64. }
  65. add_action( 'admin_init', 'add_product_meta_boxes' );
  66.  
  67. function save_product_custom_fields(){
  68. global $post;
  69.  
  70. if ( $post )
  71. {
  72. update_post_meta($post->ID, "short_description", @$_POST["short_description"]);
  73. update_post_meta($post->ID, "price", @$_POST["price"]);
  74. update_post_meta($post->ID, "length", @$_POST["length"]);
  75. update_post_meta($post->ID,'product_ship_lead_days',@$_POST['ship_lead_days']);
  76. update_post_meta($post->ID,'commision_broker',@$_POST['commision_broker']);
  77. }
  78. }
  79. add_action( 'save_post', 'save_product_custom_fields' );
  80.  
  81. add_action( 'init', 'product_category', 0 );
  82. function product_category() {
  83. $labels = array(
  84. 'name' => _x( 'Categories', 'taxonomy general name' ),
  85. 'singular_name' => _x( 'category', 'taxonomy singular name' ),
  86. 'search_items' => __( 'Search Categories' ),
  87. 'all_items' => __( 'All Categories' ),
  88. 'parent_item' => __( 'Parent Categories' ),
  89. 'parent_item_colon' => __( 'Parent Categories:' ),
  90. 'edit_item' => __( 'Edit Categories' ),
  91. 'update_item' => __( 'Update Categories' ),
  92. 'add_new_item' => __( 'Add New Category' ),
  93. 'new_item_name' => __( 'New Category Name' ),
  94. 'menu_name' => __( 'Categories' ),
  95. );
  96.  
  97. $args = array(
  98. 'hierarchical' => true,
  99. 'labels' => $labels,
  100. 'show_ui' => true,
  101. 'show_admin_column' => true,
  102. 'query_var' => true,
  103. 'rewrite' => array( 'slug' => 'product_category' ),
  104. );
  105. register_taxonomy( 'product_category', array( 'product' ), $args );
  106.  
  107. $labels = array(
  108. 'name' => _x( 'Tag', 'taxonomy general name' ),
  109. 'singular_name' => _x( 'tag', 'taxonomy singular name' ),
  110. 'search_items' => __( 'Search tag' ),
  111. 'popular_items' => __( 'Popular tag' ),
  112. 'all_items' => __( 'All tag' ),
  113. 'parent_item' => null,
  114. 'parent_item_colon' => null,
  115. 'edit_item' => __( 'Edit tag' ),
  116. 'update_item' => __( 'Update tag' ),
  117. 'add_new_item' => __( 'Add New tag' ),
  118. 'new_item_name' => __( 'New tag Name' ),
  119. 'separate_items_with_commas' => __( 'Separate tag with commas' ),
  120. 'add_or_remove_items' => __( 'Add or remove tags' ),
  121. 'choose_from_most_used' => __( 'Choose from the most used tags' ),
  122. 'not_found' => __( 'No tag found.' ),
  123. 'menu_name' => __( 'Tags' ),
  124. );
  125.  
  126. $args = array(
  127. 'hierarchical' => FALSE,
  128. 'labels' => $labels,
  129. 'show_ui' => true,
  130. 'show_admin_column' => true,
  131. 'update_count_callback' => '_update_post_term_count',
  132. 'query_var' => true,
  133. 'rewrite' => array( 'slug' => 'product_tag' ),
  134. );
  135.  
  136. register_taxonomy( 'product_tag', 'product', $args );
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement