· 6 years ago · Jul 03, 2019, 08:02 AM
1<tr>
2 <th><?php _e('Custom Stock Message'); ?></th>
3 <td>
4 <input type="text" name="customstock-msg" value=""/>
5 </td>
6 </tr>
7
8 <tr>
9 <th><?php _e('Order Processing Time'); ?></th>
10 <td>
11
12 <input type="text" name="customstock-Processing-time">
13 </td>
14 </tr>
15
16 <tr>
17 <th><?php _e('Instock Date'); ?></th>
18 <td>
19 <!-- <input type="date" name="customstock-date" value=""/>-->
20 <input type="text" id="datepicker" name="customstock-instockdate">
21 </td>
22 </tr>
23
24 <tr>
25 <th><?php _e('Show Quantity when Instock'); ?></th>
26 <td>
27 <!-- <input type="date" name="customstock-date" value=""/>-->
28 <select name="customstock-quantity" id="showquantity">
29 <option value="yes">Yes</option>
30 <option value="no"> No</option>
31 </select>
32 </td>
33 </tr>
34
35 <tr>
36 <th><?php _e('Show on Catlog Page'); ?></th>
37 <td>
38 <!-- <input type="date" name="customstock-date" value=""/>-->
39 <select name="customstock-catlogpage" id="showcatlogpage">
40 <option value="yes">Yes</option>
41 <option value="no"> No</option>
42 </select>
43 </td>
44 </tr>
45
46 ?>
47
48 <p>
49 <input type="submit" class="button-primary" name="customstock_submit_specific_product" value="<?php _e('Save Changes') ?>" />
50 </p>
51 </form>
52
53 if(isset($_POST['customstock_submit_specific_product']))
54 {
55 global $wpdb,$product;
56 $id = $product->id;
57
58 $custommsg = sanitize_text_field( $_POST['customstock-msg'] );
59 $customprocessingtime = sanitize_text_field( $_POST['customstock-Processing-time'] );
60 $customstockquantity = sanitize_text_field( $_POST['customstock-quantity'] );
61 $customstockcatlogpage = sanitize_text_field( $_POST['customstock-catlogpage'] );
62 $customstockinstockdate = sanitize_text_field( $_POST['customstock-instockdate'] );
63 $customstockinstockdate = date("Y-m-d", strtotime($customstockinstockdate) );
64
65 $wpdb->insert('wp_woocommerce_specific_product_settings', array(
66 'custom_msg' => $custommsg,
67 'order_processing_time' => $customprocessingtime,
68 'exp_instock_date' => $customstockinstockdate,
69 'show_stockstatus_quantity' => $customstockquantity,
70 'showon_catlog' => $customstockcatlogpage,
71 'specific_product_id' => $id
72 ));
73 }
74
75<?php
76/**
77 * Database
78 *
79 * Add custom tables to a WordPress database
80 */
81
82if ( ! class_exists('DB_Table') ) :
83
84class DB_Table
85{
86 protected $table;
87
88 /**
89 * Create Database Table
90 *
91 * Given a schema array, create a custom table in the WP database
92 */
93 public static function create() {
94 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
95
96 global $wpdb, $charset_collate;
97
98 $table = 'custom_table_name'; // The name of your custom DB table
99 $schema = self::schema();
100
101 // create database table
102 $table_name = $wpdb->prefix . $table;
103 $sql = "CREATE TABLE IF NOT EXISTS $table_name ( ";
104 $sql .= $schema;
105 $sql .= " ) $charset_collate;";
106
107 // run create process
108 dbDelta( $sql );
109 }
110
111 /**
112 * Schema: Level Term Rates
113 *
114 * Schema definition for the custom table
115 */
116 public static function schema() {
117
118 // Define your schema here for the table
119 $schema = "id int(8) unsigned NOT NULL AUTO_INCREMENT,
120 age int(3) NOT NULL DEFAULT '0',
121 first_name text NOT NULL DEFAULT '',
122 last_name text NOT NULL DEFAULT '',
123 gender char(1) NOT NULL DEFAULT '',
124 PRIMARY KEY (id)";
125
126 return $schema;
127 }
128}
129
130/**
131 * Register Hooks
132 */
133register_activation_hook( __FILE__, array( 'DB_Table', 'create' ) );
134
135endif;
136?>