| @@ -1,2231 +1,3202 @@ | ||
| 1 | -<?php | |
| 2 | -function usces_get_post_meta_by_metaid( $meta_id ) { | |
| 3 | - global $wpdb; | |
| 4 | - $res = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id), ARRAY_A); | |
| 5 | - return $res; | |
| 6 | -} | |
| 7 | -function usces_get_post_meta( $post_id, $key ) { | |
| 8 | - global $wpdb; | |
| 9 | - $res = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $key), ARRAY_A); | |
| 10 | - return $res; | |
| 11 | -} | |
| 12 | -function usces_sort_post_meta( $post_id, $metastr ) { | |
| 13 | - global $wpdb; | |
| 14 | - $meta_ids = explode(',', $metastr); | |
| 15 | - if( !empty($meta_ids) ){ | |
| 16 | - $i = 0; | |
| 17 | - foreach( $meta_ids as $meta_id ){ | |
| 18 | - | |
| 19 | - $rows = usces_get_post_meta_by_metaid( $meta_id ); | |
| 20 | - $values = unserialize($rows['meta_value']); | |
| 21 | - $values['sort'] = $i; | |
| 22 | - $serialized_values = serialize($values); | |
| 23 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $rows['meta_id']) ); | |
| 24 | - $i++; | |
| 25 | - } | |
| 26 | - } | |
| 27 | - return; | |
| 28 | -} | |
| 29 | - | |
| 30 | -/** | |
| 31 | - * item option | |
| 32 | - */ | |
| 33 | -//function has_item_option_meta( $postid ) { | |
| 34 | -function usces_get_opts( $post_id, $keyflag = 'sort' ) { | |
| 35 | - $opts = array(); | |
| 36 | - $metas = usces_get_post_meta($post_id, '_iopt_'); | |
| 37 | - | |
| 38 | - if( empty($metas) ) return $opts; | |
| 39 | - | |
| 40 | - foreach( $metas as $rows ){ | |
| 41 | - $values = unserialize($rows['meta_value']); | |
| 42 | - $key = isset($values[$keyflag]) ? $values[$keyflag] : $values['sort']; | |
| 43 | - $opts[$key] = array( | |
| 44 | - 'meta_id' => $rows['meta_id'], | |
| 45 | - 'name' => $values['name'], | |
| 46 | - 'means' => $values['means'], | |
| 47 | - 'essential' => $values['essential'], | |
| 48 | - 'value' => $values['value'], | |
| 49 | - 'sort' => $values['sort'] | |
| 50 | - ); | |
| 51 | - } | |
| 52 | - ksort($opts); | |
| 53 | - | |
| 54 | - return $opts; | |
| 55 | -} | |
| 56 | -function usces_add_opt( $post_id, $newvalue, $check = true ) { | |
| 57 | - global $wpdb, $usces; | |
| 58 | - if( $check ){ | |
| 59 | - $metas = usces_get_post_meta($post_id, '_iopt_'); | |
| 60 | - if( !empty($metas) ){ | |
| 61 | - $meta_num = count($metas); | |
| 62 | - $unique = true; | |
| 63 | - $sortnull = true; | |
| 64 | - foreach( $metas as $meta ){ | |
| 65 | - $values = unserialize($meta['meta_value']); | |
| 66 | - if( $values['name'] == $newvalue['name'] ) | |
| 67 | - $unique = false; | |
| 68 | - if( !isset($values['sort']) ) | |
| 69 | - $sortnull = false; | |
| 70 | - $sort[] = $values['sort']; | |
| 71 | - } | |
| 72 | - if( !$unique ) | |
| 73 | - return -1; | |
| 74 | - | |
| 75 | - rsort($sort); | |
| 76 | - $next_number = reset($sort) + 1; | |
| 77 | - $unique_sort = array_unique($sort); | |
| 78 | - if( $meta_num !== count($unique_sort) || $meta_num !== $next_number || !$sortnull){ | |
| 79 | - //To repair the sort data | |
| 80 | - $i = 0; | |
| 81 | - foreach( $metas as $rows ){ | |
| 82 | - $values = unserialize($rows['meta_value']); | |
| 83 | - $values['sort'] = $i; | |
| 84 | - $serialized_values = serialize($values); | |
| 85 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $rows['meta_id']) ); | |
| 86 | - $i++; | |
| 87 | - } | |
| 88 | - } | |
| 89 | - } | |
| 90 | - $newvalue['sort'] = !empty($meta_num) ? $meta_num : 0; | |
| 91 | - } | |
| 92 | - $serialized_newvalue = serialize($newvalue); | |
| 93 | - $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value ) VALUES (%d, '_iopt_', %s)", $post_id, $serialized_newvalue) ); | |
| 94 | - $id = $wpdb->insert_id; | |
| 95 | - return $id; | |
| 96 | -} | |
| 97 | - | |
| 98 | -/** | |
| 99 | - * item sku | |
| 100 | - */ | |
| 101 | -function usces_add_sku( $post_id, $newvalue, $check = true ) { | |
| 102 | - global $wpdb, $usces; | |
| 103 | - if( $check ){ | |
| 104 | - $metas = usces_get_post_meta($post_id, '_isku_'); | |
| 105 | - if( !empty($metas) ){ | |
| 106 | - $meta_num = count($metas); | |
| 107 | - $unique = true; | |
| 108 | - $sortnull = true; | |
| 109 | - foreach( $metas as $rows ){ | |
| 110 | - $values = unserialize($rows['meta_value']); | |
| 111 | - if( $values['code'] == $newvalue['code'] ) | |
| 112 | - $unique = false; | |
| 113 | - if( !isset($values['sort']) ) | |
| 114 | - $sortnull = false; | |
| 115 | - $sort[] = $values['sort']; | |
| 116 | - } | |
| 117 | - if( !$unique ) | |
| 118 | - return -1; | |
| 119 | - | |
| 120 | - rsort($sort); | |
| 121 | - $next_number = $sort[0] + 1; | |
| 122 | - $unique_sort = array_unique($sort); | |
| 123 | - if( $meta_num != count($unique_sort) || $meta_num != $next_number || !$sortnull){ | |
| 124 | - //To repair the sort data | |
| 125 | - $i = 0; | |
| 126 | - foreach( $metas as $rows ){ | |
| 127 | - $values = unserialize($rows['meta_value']); | |
| 128 | - $values['sort'] = $i; | |
| 129 | - $serialized_values = serialize($values); | |
| 130 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $rows['meta_id']) ); | |
| 131 | - $i++; | |
| 132 | - } | |
| 133 | - } | |
| 134 | - } | |
| 135 | - $newvalue['sort'] = !empty($meta_num) ? $meta_num : 0; | |
| 136 | - } | |
| 137 | - $newvalue = $usces->stripslashes_deep_post($newvalue); | |
| 138 | - $serialized_newvalue = serialize($newvalue); | |
| 139 | - $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value ) VALUES (%d, '_isku_', %s)", $post_id, $serialized_newvalue) ); | |
| 140 | - $id = $wpdb->insert_id; | |
| 141 | - return $id; | |
| 142 | -} | |
| 143 | - | |
| 144 | - | |
| 145 | -/** | |
| 146 | - * list_item_option | |
| 147 | - */ | |
| 148 | -function list_item_option_meta( $opts ) { | |
| 149 | - // Exit if no meta | |
| 150 | - if ( ! $opts ) { | |
| 151 | - ?> | |
| 152 | - <table id="optlist-table" class="list" style="display: none;"> | |
| 153 | - <thead> | |
| 154 | - <tr> | |
| 155 | - <th class="hanldh"> </th> | |
| 156 | - <th class="item-opt-key"><?php _e('option name','usces') ?></th> | |
| 157 | - <th class="item-opt-value"><?php _e('selected amount','usces') ?></th> | |
| 158 | - </tr> | |
| 159 | - </thead> | |
| 160 | - <tbody id="item-opt-list"> | |
| 161 | - <tr><td></td></tr> | |
| 162 | - </tbody> | |
| 163 | - </table> | |
| 164 | - <?php | |
| 165 | - }else{ | |
| 166 | - ?> | |
| 167 | - <table id="optlist-table" class="list"> | |
| 168 | - <thead> | |
| 169 | - <tr> | |
| 170 | - <th class="hanldh"> </th> | |
| 171 | - <th class="item-opt-key"><?php _e('option name','usces') ?></th> | |
| 172 | - <th class="item-opt-value"><?php _e('selected amount','usces') ?></th> | |
| 173 | - </tr> | |
| 174 | - </thead> | |
| 175 | - <tbody id="item-opt-list"> | |
| 176 | - <?php | |
| 177 | - foreach ( $opts as $opt ) | |
| 178 | - echo _list_item_option_meta_row( $opt ); | |
| 179 | - ?> | |
| 180 | - </tbody> | |
| 181 | - </table> | |
| 182 | - <?php | |
| 183 | - } | |
| 184 | -} | |
| 185 | - | |
| 186 | -/** | |
| 187 | - * list_item_sku | |
| 188 | - */ | |
| 189 | -function list_item_sku_meta( $skus ) { | |
| 190 | - // Exit if no meta | |
| 191 | - if ( empty( $skus ) ) { | |
| 192 | - ?> | |
| 193 | - <table id="skulist-table" class="list" style="display: none;"> | |
| 194 | - <thead> | |
| 195 | - <tr> | |
| 196 | - <th class="hanldh" rowspan="2"> </th> | |
| 197 | - <th><?php _e('SKU code','usces'); ?></th> | |
| 198 | - <th><?php echo apply_filters('usces_filter_listprice_label', __('normal price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> | |
| 199 | - <th><?php echo apply_filters('usces_filter_sellingprice_label', __('Sale price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> | |
| 200 | - <th><?php _e('stock','usces'); ?></th> | |
| 201 | - <th><?php _e('stock status', 'usces'); ?></th> | |
| 202 | - </tr> | |
| 203 | - </thead> | |
| 204 | - <tbody id="item-sku-list"> | |
| 205 | - <tr><td></td><td></td><td></td><td></td><td></td></tr> | |
| 206 | - </tbody> | |
| 207 | - </table> | |
| 208 | - <?php | |
| 209 | - }else{ | |
| 210 | - ?> | |
| 211 | - <table id="skulist-table" class="list"> | |
| 212 | - <thead> | |
| 213 | - <tr> | |
| 214 | - <th class="hanldh" rowspan="2"> </th> | |
| 215 | - <th class="item-sku-key"><?php _e('SKU code','usces'); ?></th> | |
| 216 | - <th class="item-sku-cprice"><?php echo apply_filters('usces_filter_listprice_label', __('normal price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> | |
| 217 | - <th class="item-sku-price"><?php echo apply_filters('usces_filter_sellingprice_label', __('Sale price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> | |
| 218 | - <th class="item-sku-zaikonum"><?php _e('stock','usces'); ?></th> | |
| 219 | - <th class="item-sku-zaiko"><?php _e('stock status','usces'); ?></th> | |
| 220 | - </tr> | |
| 221 | - <tr> | |
| 222 | - <th><?php _e('SKU display name ','usces'); ?></th> | |
| 223 | - <th><?php _e('unit','usces'); ?></th> | |
| 224 | - <?php | |
| 225 | - $advance_title = '<th colspan="2"> </th>'; | |
| 226 | - echo apply_filters('usces_filter_sku_meta_form_advance_title', $advance_title); | |
| 227 | - ?> | |
| 228 | - <th><?php _e('Apply business package','usces'); ?></th> | |
| 229 | - </tr> | |
| 230 | - </thead> | |
| 231 | - <tbody id="item-sku-list"> | |
| 232 | - <?php | |
| 233 | - foreach ( $skus as $sku ) | |
| 234 | - echo _list_item_sku_meta_row( $sku ); | |
| 235 | - ?> | |
| 236 | - </tbody> | |
| 237 | - </table> | |
| 238 | - <?php | |
| 239 | - } | |
| 240 | -} | |
| 241 | - | |
| 242 | - | |
| 243 | - | |
| 244 | -/** | |
| 245 | - * option meta row | |
| 246 | - */ | |
| 247 | -function _list_item_option_meta_row( $opt ) { | |
| 248 | - $r = ''; | |
| 249 | - $style = ''; | |
| 250 | - $means = get_option('usces_item_option_select'); | |
| 251 | - | |
| 252 | -// $opt['meta_value'] = unserialize( $opt['meta_value'] ); | |
| 253 | - | |
| 254 | - $name = esc_attr($opt['name']); | |
| 255 | - $meansoption = ''; | |
| 256 | - foreach($means as $meankey => $meanvalue){ | |
| 257 | - if($meankey == $opt['means']) { | |
| 258 | - $selected = ' selected="selected"'; | |
| 259 | - }else{ | |
| 260 | - $selected = ''; | |
| 261 | - } | |
| 262 | - $meansoption .= '<option value="' . esc_attr($meankey) . '"' . $selected . '>' . esc_html($meanvalue) . "</option>\n"; | |
| 263 | - } | |
| 264 | - $essential = $opt['essential'] == 1 ? " checked='checked'" : ""; | |
| 265 | - $value = ''; | |
| 266 | - if(is_array($opt['value'])){ | |
| 267 | - foreach($opt['value'] as $k => $v){ | |
| 268 | - $value .= $v . "\n"; | |
| 269 | - } | |
| 270 | - }else{ | |
| 271 | - //$value = esc_attr(trim($opt['value'])); | |
| 272 | - $value = $opt['value']; | |
| 273 | - } | |
| 274 | - $value = trim($value); | |
| 275 | - $id = (int) $opt['meta_id']; | |
| 276 | - $sort = (int) $opt['sort']; | |
| 277 | - | |
| 278 | - ob_start(); | |
| 279 | - ?> | |
| 280 | - <tr class="metastuffrow"><td colspan="3"> | |
| 281 | - <table id="itemopt-<?php echo $id; ?>" class="metastufftable"> | |
| 282 | - <tr> | |
| 283 | - <th class='handlb' rowspan='2'> </th> | |
| 284 | - <td class='item-opt-key'> | |
| 285 | - <div><input name='itemopt[<?php echo $id; ?>][name]' id='itemopt[<?php echo $id; ?>][name]' class='metaboxfield' type='text' size='20' value='<?php echo $name; ?>' /></div> | |
| 286 | - <div class='optcheck'> | |
| 287 | - <select name='itemopt[<?php echo $id; ?>][means]' id='itemopt[<?php echo $id; ?>][means]'><?php echo $meansoption; ?></select> | |
| 288 | - <label for='itemopt[<?php echo $id; ?>][essential]'><input name='itemopt[<?php echo $id; ?>][essential]' id='itemopt[<?php echo $id; ?>][essential]' type='checkbox' value='1'<?php echo $essential; ?> class='metaboxcheckfield' /><?php _e('Required','usces'); ?></label> | |
| 289 | - </div> | |
| 290 | - </td> | |
| 291 | - <td class='item-opt-value'> | |
| 292 | - <textarea name='itemopt[<?php echo $id; ?>][value]' id='itemopt[<?php echo $id; ?>][value]' class='metaboxfield'><?php echo esc_html($value); ?></textarea> | |
| 293 | - </td> | |
| 294 | - </tr> | |
| 295 | - <tr> | |
| 296 | - <td colspan='2' class='submittd'> | |
| 297 | - <div id='itemoptsubmit-<?php echo $id; ?>' class='submit'> | |
| 298 | - <input name='deleteitemopt[<?php echo $id; ?>]' id='deleteitemopt[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Delete' )); ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('deleteitemopt', <?php echo $id; ?>);" /> | |
| 299 | - <input name='updateitemopt[<?php echo $id; ?>]' id='updateitemopt[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Update' )); ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('updateitemopt', <?php echo $id; ?>);" /> | |
| 300 | - <input name='itemopt[<?php echo $id; ?>][sort]' id='itemopt[<?php echo $id; ?>][sort]' type='hidden' value='<?php echo $sort; ?>' /> | |
| 301 | - </div> | |
| 302 | - <div id='itemopt_loading-<?php echo $id; ?>' class='meta_submit_loading'></div> | |
| 303 | - </td> | |
| 304 | - </tr> | |
| 305 | - </table> | |
| 306 | - </td></tr> | |
| 307 | - <?php | |
| 308 | - $r = ob_get_contents(); | |
| 309 | - ob_end_clean(); | |
| 310 | - return $r; | |
| 311 | -} | |
| 312 | - | |
| 313 | -/** | |
| 314 | - * sku meta row | |
| 315 | - */ | |
| 316 | -function _list_item_sku_meta_row( $sku ) { | |
| 317 | - $r = ''; | |
| 318 | - $style = ''; | |
| 319 | - | |
| 320 | - $key = esc_attr($sku['code']); | |
| 321 | - $cprice = $sku['cprice']; | |
| 322 | - $price = $sku['price']; | |
| 323 | - $zaikonum = $sku['stocknum']; | |
| 324 | - $zaiko = $sku['stock']; | |
| 325 | - $skudisp = esc_attr($sku['name']); | |
| 326 | - $skuunit = esc_attr($sku['unit']); | |
| 327 | - $skugptekiyo = $sku['gp']; | |
| 328 | - //$charging_type = $sku['meta_value']['charging_type']; | |
| 329 | - $id = (int)$sku['meta_id']; | |
| 330 | - $zaikoselectarray = get_option('usces_zaiko_status'); | |
| 331 | - $sort = (int) $sku['sort']; | |
| 332 | - | |
| 333 | - ob_start(); | |
| 334 | - ?> | |
| 335 | - <tr class='metastuffrow'><td colspan='6'> | |
| 336 | - <table id='itemsku-<?php echo $id; ?>' class='metastufftable'> | |
| 337 | - <tr> | |
| 338 | - <th class='handlb' rowspan='<?php echo apply_filters( 'usces_filter_sku_meta_rowspan', '3' ); ?>'> </th> | |
| 339 | - <td class='item-sku-key'><input name='itemsku[<?php echo $id; ?>][key]' id='itemsku[<?php echo $id; ?>][key]' class='skuname metaboxfield' type='text' value='<?php echo $key; ?>' /></td> | |
| 340 | - <td class='item-sku-cprice'><input name='itemsku[<?php echo $id; ?>][cprice]' id='itemsku[<?php echo $id; ?>][cprice]' class='skuprice metaboxfield' type='text' value='<?php echo $cprice; ?>' /></td> | |
| 341 | - <td class='item-sku-price'><input name='itemsku[<?php echo $id; ?>][price]' id='itemsku[<?php echo $id; ?>][price]' class='skuprice metaboxfield' type='text' value='<?php echo $price; ?>' /></td> | |
| 342 | - <td class='item-sku-zaikonum'><input name='itemsku[<?php echo $id; ?>][zaikonum]' id='itemsku[<?php echo $id; ?>][zaikonum]' class='skuzaikonum metaboxfield' type='text' value='<?php echo $zaikonum; ?>' /></td> | |
| 343 | - <td class='item-sku-zaiko'> | |
| 344 | - <select id='itemsku[<?php echo $id; ?>][zaiko]' name='itemsku[<?php echo $id; ?>][zaiko]' class='skuzaiko metaboxfield'> | |
| 345 | - <?php | |
| 346 | - for ( $i=0; $i<count($zaikoselectarray); $i++ ) { | |
| 347 | - $selected = ( $i == $zaiko ) ? " selected='selected'" : ''; | |
| 348 | - ?> | |
| 349 | - <option value='<?php echo $i; ?>'<?php echo $selected; ?>><?php echo $zaikoselectarray[$i]; ?></option> | |
| 350 | - <?php | |
| 351 | - } | |
| 352 | - ?> | |
| 353 | - </select> | |
| 354 | - </td> | |
| 355 | - </tr> | |
| 356 | - <tr> | |
| 357 | - <td class='item-sku-key'><input name='itemsku[<?php echo $id; ?>][skudisp]' id='itemsku[<?php echo $id; ?>][skudisp]' class='skudisp metaboxfield' type='text' value='<?php echo $skudisp; ?>' /> | |
| 358 | - </td> | |
| 359 | - <td class='item-sku-cprice'><input name='itemsku[<?php echo $id; ?>][skuunit]' id='itemsku[<?php echo $id; ?>][skuunit]' class='skuunit metaboxfield' type='text' value='<?php echo $skuunit; ?>' /></td> | |
| 360 | - <?php | |
| 361 | - $default_field = "\n\t\t<td colspan='2'> </td>"; | |
| 362 | - echo apply_filters('usces_filter_sku_meta_row_advance', $default_field, $sku); | |
| 363 | - ?> | |
| 364 | - <td class='item-sku-zaiko'> | |
| 365 | - <select id='itemsku[<?php echo $id; ?>][skugptekiyo]' name='itemsku[<?php echo $id; ?>][skugptekiyo]' class='skugptekiyo metaboxfield'> | |
| 366 | - <option value='0' <?php echo ($skugptekiyo == 0 ? " selected='selected'" : ""); ?>><?php _e('Not apply','usces'); ?></option> | |
| 367 | - <option value='1' <?php echo ($skugptekiyo == 1 ? " selected='selected'" : ""); ?>><?php _e('Apply','usces'); ?></option> | |
| 368 | - </select> | |
| 369 | - </td> | |
| 370 | - </tr> | |
| 371 | - <?php echo apply_filters( 'usces_filter_sku_meta_row', '', $sku ); ?> | |
| 372 | - <tr> | |
| 373 | - <td colspan='5' class='submittd'> | |
| 374 | - <div id='skusubmit-<?php echo $id; ?>' class='submit'> | |
| 375 | - <input name='deleteitemsku[<?php echo $id; ?>]' id='deleteitemsku[<?php echo $id; ?>]' type='button' value='<?php esc_attr_e(__( 'Delete' )) ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('deleteitemsku', <?php echo $id; ?>);" /> | |
| 376 | - <input name='updateitemsku[<?php echo $id; ?>]' id='updateitemsku[<?php echo $style; ?>]' type='button' value='<?php esc_attr_e(__( 'Update' )); ?>' onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('updateitemsku', <?php echo $id; ?>);" /> | |
| 377 | - <input name='itemsku[<?php echo $id; ?>][sort]' id='itemsku[<?php echo $id; ?>][sort]' type='hidden' value='<?php echo $sort; ?>' /> | |
| 378 | - </div> | |
| 379 | - <div id='itemsku_loading-<?php echo $id; ?>' class='meta_submit_loading'></div> | |
| 380 | - </td> | |
| 381 | - </tr> | |
| 382 | - </table> | |
| 383 | - </td></tr> | |
| 384 | - <?php | |
| 385 | - $r = ob_get_contents(); | |
| 386 | - ob_end_clean(); | |
| 387 | - return $r; | |
| 388 | -} | |
| 389 | - | |
| 390 | - | |
| 391 | -/** | |
| 392 | - * common_option_meta_form | |
| 393 | - */ | |
| 394 | -function common_option_meta_form() { | |
| 395 | - $means = get_option('usces_item_option_select'); | |
| 396 | - $meansoption = ''; | |
| 397 | - foreach($means as $meankey => $meanvalue){ | |
| 398 | - $meansoption .= '<option value="' . esc_attr($meankey) . '">' . esc_html($meanvalue) . "</option>\n"; | |
| 399 | - } | |
| 400 | - ?> | |
| 401 | - <div id="itemopt_ajax-response"></div> | |
| 402 | - <p><strong><?php _e('Add a new option','usces') ?> : </strong></p> | |
| 403 | - <table id="newmeta2"> | |
| 404 | - <thead> | |
| 405 | - <tr> | |
| 406 | - <th class="left"><label for="metakeyselect"><?php _e('option name','usces') ?></label></th> | |
| 407 | - <th><label for="metavalue"><?php _e('selected amount','usces') ?></label></th> | |
| 408 | - </tr> | |
| 409 | - </thead> | |
| 410 | - | |
| 411 | - <tbody> | |
| 412 | - <tr> | |
| 413 | - <td class='item-opt-key'> | |
| 414 | - <input type="text" id="newoptname" name="newoptname" class="metaboxfield" tabindex="7" value="" /> | |
| 415 | - <div class="optcheck"> | |
| 416 | - <select name='newoptmeans' id='newoptmeans' class="metaboxfield long"><?php echo $meansoption; ?></select> | |
| 417 | - <label for='newoptessential'><input name="newoptessential" type="checkbox" id="newoptessential" class="metaboxcheckfield" /><?php _e('Required','usces') ?></label> | |
| 418 | - </div> | |
| 419 | - </td> | |
| 420 | - <td class='item-opt-value'><textarea id="newoptvalue" name="newoptvalue" class='metaboxfield'></textarea></td> | |
| 421 | - </tr> | |
| 422 | - | |
| 423 | - <tr> | |
| 424 | - <td colspan="2" class="submittd"> | |
| 425 | - <div id='newcomoptsubmit' class='submit'> | |
| 426 | - <input name="add_comopt" type="button" id="add_comopt" tabindex="9" value="<?php _e('Add common options','usces') ?>" onclick="itemOpt.post('addcommonopt', 0);" /> | |
| 427 | - </div> | |
| 428 | - <div id="newcomopt_loading" class="meta_submit_loading"></div> | |
| 429 | - </td> | |
| 430 | - </tr> | |
| 431 | - </tbody> | |
| 432 | - </table> | |
| 433 | - <?php | |
| 434 | -} | |
| 435 | - | |
| 436 | -/** | |
| 437 | - * item_option_meta_form | |
| 438 | - */ | |
| 439 | -function item_option_meta_form() { | |
| 440 | - global $wpdb; | |
| 441 | - $usces_options = get_option('usces'); | |
| 442 | - $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); | |
| 443 | - $cart_number = (int)get_option('usces_cart_number'); | |
| 444 | - $opts = usces_get_opts($cart_number); | |
| 445 | - $means = get_option('usces_item_option_select'); | |
| 446 | - $meansoption = ''; | |
| 447 | - foreach($means as $meankey => $meanvalue){ | |
| 448 | - $meansoption .= '<option value="' . esc_attr($meankey) . '">' . esc_html($meanvalue) . "</option>\n"; | |
| 449 | - } | |
| 450 | - ?> | |
| 451 | - <div id="itemopt_ajax-response"></div> | |
| 452 | - <p><strong><?php _e('Applicable product options','usces') ?> : </strong></p> | |
| 453 | - <table id="newmeta2"> | |
| 454 | - <thead> | |
| 455 | - <tr> | |
| 456 | - <th class="item-opt-key"><label for="metakeyselect"><?php _e('option name','usces') ?></label></th> | |
| 457 | - <th class="item-opt-value"><label for="metavalue"><?php _e('selected amount','usces') ?></label></th> | |
| 458 | - </tr> | |
| 459 | - </thead> | |
| 460 | - | |
| 461 | - <tbody> | |
| 462 | - <tr> | |
| 463 | - <td class='item-opt-key'> | |
| 464 | - <?php if ( !empty($opts) ) { ?> | |
| 465 | - <select id="optkeyselect" name="optkeyselect" class="optkeyselect metaboxfield" tabindex="7" onchange="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('keyselect', this.value);"> | |
| 466 | - <option value="#NONE#"><?php _e( '-- Select --','usces' ); ?></option> | |
| 467 | - <?php foreach ( $opts as $opt ){ ?> | |
| 468 | - <option value='<?php echo $opt['meta_id']; ?>'><?php esc_attr_e($opt['name']); ?></option> | |
| 469 | - <?php } ?> | |
| 470 | - </select> | |
| 471 | - <input type="hidden" id="newoptname" name="newoptname" class="metaboxfield" /> | |
| 472 | - <div class="optcheck"> | |
| 473 | - <select name='newoptmeans' id='newoptmeans'><?php echo $meansoption; ?></select> | |
| 474 | - <label for='newoptessential'><input name="newoptessential" type="checkbox" id="newoptessential" class="metaboxcheckfield" /><?php _e('Required','usces') ?></label> | |
| 475 | - </div> | |
| 476 | - <?php } else { ?> | |
| 477 | - <p><?php _e('Please create a common option.','usces') ?></p> | |
| 478 | - <?php } ?> | |
| 479 | - </td> | |
| 480 | - <td class='item-opt-value'><textarea id="newoptvalue" name="newoptvalue" class='metaboxfield'></textarea></td> | |
| 481 | - </tr> | |
| 482 | - | |
| 483 | - <tr> | |
| 484 | - <td colspan="2" class="submittd"> | |
| 485 | - <?php if( is_array($opts) ) { ?> | |
| 486 | - <div id='newitemoptsubmit' class='submit'> | |
| 487 | - <input name="add_itemopt" type="button" id="add_itemopt" tabindex="9" value="<?php _e('Apply an option','usces') ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('additemopt', 0);" /> | |
| 488 | - </div> | |
| 489 | - <div id="newitemopt_loading" class="meta_submit_loading"></div> | |
| 490 | - <?php } ?> | |
| 491 | - </td> | |
| 492 | - </tr> | |
| 493 | - </tbody> | |
| 494 | - </table> | |
| 495 | - <?php | |
| 496 | -} | |
| 497 | - | |
| 498 | -/** | |
| 499 | - * item_sku_meta_form | |
| 500 | - */ | |
| 501 | -function item_sku_meta_form() { | |
| 502 | - ?> | |
| 503 | - <div id="sku_ajax-response"></div> | |
| 504 | - <p><strong><?php _e('Add new SKU','usces') ?> : </strong></p> | |
| 505 | - <table id="newsku"> | |
| 506 | - <thead> | |
| 507 | - <tr> | |
| 508 | - <th class="left"><?php _e('SKU code','usces') ?></th> | |
| 509 | - <th><?php echo apply_filters('usces_filter_listprice_label', __('normal price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> | |
| 510 | - <th><?php echo apply_filters('usces_filter_sellingprice_label', __('Sale price','usces'), NULL, NULL); ?>(<?php usces_crcode(); ?>)</th> | |
| 511 | - <th><?php _e('stock','usces') ?></th> | |
| 512 | - <th><?php _e('stock status','usces') ?></th> | |
| 513 | - </tr> | |
| 514 | - <tr> | |
| 515 | - <th><?php _e('SKU display name ','usces') ?></th> | |
| 516 | - <th><?php _e('unit','usces') ?></th> | |
| 517 | - <?php | |
| 518 | - $advance_title = '<th colspan="2"> </th>'; | |
| 519 | - echo apply_filters('usces_filter_sku_meta_form_advance_title', $advance_title); | |
| 520 | - ?> | |
| 521 | - <th><?php _e('Apply business package','usces') ?></th> | |
| 522 | - </tr> | |
| 523 | - </thead> | |
| 524 | - | |
| 525 | - <tbody> | |
| 526 | - <tr> | |
| 527 | - <td id="newskuleft" class='item-sku-key'><input type="text" id="newskuname" name="newskuname" class="newskuname metaboxfield"value="" /></td> | |
| 528 | - <td class='item-sku-cprice'><input type="text" id="newskucprice" name="newskucprice" class='newskuprice metaboxfield' /></td> | |
| 529 | - <td class='item-sku-price'><input type="text" id="newskuprice" name="newskuprice" class='newskuprice metaboxfield' /></td> | |
| 530 | - <td class='item-sku-zaikonum'><input type="text" id="newskuzaikonum" name="newskuzaikonum" class='newskuzaikonum metaboxfield' /></td> | |
| 531 | - <td class='item-sku-zaiko'> | |
| 532 | - <select id="newskuzaikoselect" name="newskuzaikoselect" class="newskuzaikoselect metaboxfield"> | |
| 533 | - <?php | |
| 534 | - $zaikoselectarray = get_option('usces_zaiko_status'); | |
| 535 | - foreach ( $zaikoselectarray as $v => $l ) { | |
| 536 | - echo "\n<option value='" . esc_attr($v) . "'>" . esc_html($l) . "</option>"; | |
| 537 | - } | |
| 538 | - ?> | |
| 539 | - </select> | |
| 540 | - </td> | |
| 541 | - </tr> | |
| 542 | - <tr> | |
| 543 | - <td class='item-sku-key'><input type="text" id="newskudisp" name="newskudisp" class="newskudisp metaboxfield" /></td> | |
| 544 | - <td class='item-sku-cprice'><input type="text" id="newskuunit" name="newskuunit" class='newskuunit metaboxfield' /></td> | |
| 545 | - <?php | |
| 546 | - $advance_field = '<td class="item-sku-price"> </td><td class="item-sku-zaikonum"> </td>'; | |
| 547 | - echo apply_filters('usces_filter_sku_meta_form_advance_field', $advance_field ); | |
| 548 | - ?> | |
| 549 | - <td class='item-sku-zaiko'> | |
| 550 | - <select id="newskugptekiyo" name="newskugptekiyo" class="newskugptekiyo metaboxfield"> | |
| 551 | - <option value="0"><?php _e('Not apply','usces') ?></option> | |
| 552 | - <option value="1"><?php _e('Apply','usces') ?></option> | |
| 553 | - </select> | |
| 554 | - </td> | |
| 555 | - </tr> | |
| 556 | - <?php echo apply_filters( 'usces_filter_newsku_meta_row', '' ); ?> | |
| 557 | - <tr> | |
| 558 | - <td colspan="5" class="submittd"> | |
| 559 | - <div id='newskusubmit' class='submit'><input name="add_itemsku" type="button" id="add_itemsku" tabindex="9" value="<?php _e('Add SKU','usces') ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('additemsku', 0);" /></div> | |
| 560 | - <div id="newitemsku_loading" class="meta_submit_loading"></div> | |
| 561 | - </td> | |
| 562 | - </tr> | |
| 563 | - </tbody> | |
| 564 | - </table> | |
| 565 | - <?php | |
| 566 | -} | |
| 567 | - | |
| 568 | - | |
| 569 | -// | |
| 570 | -// Post Meta | |
| 571 | -// | |
| 572 | - | |
| 573 | -/** | |
| 574 | - * add_item_option_meta | |
| 575 | - */ | |
| 576 | -function add_item_option_meta( $post_ID ) { | |
| 577 | - global $usces; | |
| 578 | - | |
| 579 | - $post_ID = (int) $post_ID; | |
| 580 | - $value = array(); | |
| 581 | - $opts = array(); | |
| 582 | - $protected = array( '#NONE#', '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); | |
| 583 | - | |
| 584 | - $newoptname = isset($_POST['newoptname']) ? trim( $_POST['newoptname'] ) : ''; | |
| 585 | - $newoptmeans = isset($_POST['newoptmeans']) ? (int)$_POST['newoptmeans']: 0; | |
| 586 | - $newoptessential = isset($_POST['newoptessential']) ? $_POST['newoptessential']: 0; | |
| 587 | - $newoptvalue = isset($_POST['newoptvalue']) ? trim($_POST['newoptvalue']) : ''; | |
| 588 | - | |
| 589 | - if ( ($newoptmeans >= 2 || WCUtils::is_zero($newoptvalue) || !empty ( $newoptvalue )) && !empty ( $newoptname) ) { | |
| 590 | - | |
| 591 | - if ( $newoptname ) | |
| 592 | - $metakey = $newoptname; // default | |
| 593 | - | |
| 594 | - if ( in_array($metakey, $protected) ) | |
| 595 | - return false; | |
| 596 | - | |
| 597 | - wp_cache_delete($post_ID, 'post_meta'); | |
| 598 | - | |
| 599 | - $value['name'] = str_replace("\\",'',$newoptname); | |
| 600 | - $value['means'] = $newoptmeans; | |
| 601 | - $value['essential'] = $newoptessential; | |
| 602 | - $value['value'] = str_replace("\\",'',$newoptvalue); | |
| 603 | - $value = $usces->stripslashes_deep_post($value); | |
| 604 | - | |
| 605 | - $id = usces_add_opt($post_ID, $value); | |
| 606 | - | |
| 607 | - return $id; | |
| 608 | - } | |
| 609 | - return false; | |
| 610 | -} // add_meta | |
| 611 | - | |
| 612 | -/** | |
| 613 | - * add_item_sku_meta | |
| 614 | - */ | |
| 615 | -function add_item_sku_meta( $post_ID ) { | |
| 616 | - global $usces; | |
| 617 | - | |
| 618 | - $post_ID = (int) $post_ID; | |
| 619 | - $value = array(); | |
| 620 | - $skus = array(); | |
| 621 | - $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); | |
| 622 | - | |
| 623 | - $newskuname = isset($_POST['newskuname']) ? trim( $_POST['newskuname'] ) : ''; | |
| 624 | - $newskucprice = isset($_POST['newskucprice']) ? $_POST['newskucprice']: ''; | |
| 625 | - $newskuprice = isset($_POST['newskuprice']) ? $_POST['newskuprice']: ''; | |
| 626 | - $newskuzaikonum = isset($_POST['newskuzaikonum']) ? $_POST['newskuzaikonum']: ''; | |
| 627 | - $newskuzaikoselect = isset($_POST['newskuzaikoselect']) ? $_POST['newskuzaikoselect'] : ''; | |
| 628 | - $newskudisp = isset($_POST['newskudisp']) ? trim( $_POST['newskudisp'] ) : ''; | |
| 629 | - $newskuunit = isset($_POST['newskuunit']) ? trim( $_POST['newskuunit'] ) : ''; | |
| 630 | - $newskugptekiyo = isset($_POST['newskugptekiyo']) ? $_POST['newskugptekiyo'] : ''; | |
| 631 | - | |
| 632 | - if ( !WCUtils::is_blank($newskuname) && !WCUtils::is_blank($newskuprice) && !WCUtils::is_blank($newskuzaikoselect) ) { | |
| 633 | - | |
| 634 | - if ( in_array($newskuname, $protected) ) | |
| 635 | - return false; | |
| 636 | - | |
| 637 | - wp_cache_delete($post_ID, 'post_meta'); | |
| 638 | - | |
| 639 | - $value['code'] = $newskuname; | |
| 640 | - $value['name'] = $newskudisp; | |
| 641 | - $value['cprice'] = $newskucprice; | |
| 642 | - $value['price'] = $newskuprice; | |
| 643 | - $value['unit'] = $newskuunit; | |
| 644 | - $value['stocknum'] = $newskuzaikonum; | |
| 645 | - $value['stock'] = $newskuzaikoselect; | |
| 646 | - $value['gp'] = $newskugptekiyo; | |
| 647 | - $value = apply_filters('usces_filter_add_item_sku_meta_value', $value); | |
| 648 | - | |
| 649 | - $id = usces_add_sku($post_ID, $value); | |
| 650 | - return $id; | |
| 651 | - } | |
| 652 | - return false; | |
| 653 | -} // add_meta | |
| 654 | - | |
| 655 | - | |
| 656 | - | |
| 657 | -/** | |
| 658 | - * up_item_option_meta | |
| 659 | - */ | |
| 660 | -function up_item_option_meta( $post_ID ) { | |
| 661 | - global $wpdb, $usces; | |
| 662 | - | |
| 663 | - $post_ID = (int) $post_ID; | |
| 664 | - $value = array(); | |
| 665 | - | |
| 666 | - $optmetaid = isset($_POST['optmetaid']) ? (int)$_POST['optmetaid'] : ''; | |
| 667 | - $optname = isset($_POST['optname']) ? $_POST['optname'] : ''; | |
| 668 | - $optmeans = isset($_POST['optmeans']) ? (int)$_POST['optmeans']: 0; | |
| 669 | - $optessential = isset($_POST['optessential']) ? $_POST['optessential']: 0; | |
| 670 | - $optsort = isset($_POST['sort']) ? $_POST['sort']: 0; | |
| 671 | - $optvalue = isset($_POST['optvalue']) ? trim($_POST['optvalue']) : ''; | |
| 672 | - | |
| 673 | - $metakey = '_iopt_'; | |
| 674 | - $value['name'] = str_replace("\\",'',$optname); | |
| 675 | - $value['means'] = $optmeans; | |
| 676 | - $value['essential'] = $optessential; | |
| 677 | - $value['value'] = str_replace("\\",'',$optvalue); | |
| 678 | - $value['sort'] = $optsort; | |
| 679 | - $value = $usces->stripslashes_deep_post($value); | |
| 680 | - $valueserialized = serialize($value); | |
| 681 | - | |
| 682 | - wp_cache_delete($post_ID, 'post_meta'); | |
| 683 | - | |
| 684 | - $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $optmetaid) ); | |
| 685 | - return $res; | |
| 686 | -} // update_meta | |
| 687 | - | |
| 688 | -/** | |
| 689 | - * up_item_sku_meta | |
| 690 | - */ | |
| 691 | -function up_item_sku_meta( $post_ID ) { | |
| 692 | - global $wpdb, $usces; | |
| 693 | - | |
| 694 | - $post_ID = (int) $post_ID; | |
| 695 | - $value = array(); | |
| 696 | - | |
| 697 | - $skuname = isset($_POST['skuname']) ? trim( $_POST['skuname'] ) : ''; | |
| 698 | - $skumetaid = isset($_POST['skumetaid']) ? (int)$_POST['skumetaid'] : ''; | |
| 699 | - $skucprice = isset($_POST['skucprice']) ? trim( $_POST['skucprice'] ): 0; | |
| 700 | - $skuprice = isset($_POST['skuprice']) ? trim( $_POST['skuprice'] ): 0; | |
| 701 | - $skuzaikonum = isset($_POST['skuzaikonum']) ? trim( $_POST['skuzaikonum'] ): 0; | |
| 702 | - $skuzaiko = isset($_POST['skuzaiko']) ? (int)$_POST['skuzaiko'] : ''; | |
| 703 | - $skudisp = isset($_POST['skudisp']) ? trim( $_POST['skudisp'] ): ''; | |
| 704 | - $skuunit = isset($_POST['skuunit']) ? trim( $_POST['skuunit'] ): ''; | |
| 705 | - $skugptekiyo = isset($_POST['skugptekiyo']) ? (int)$_POST['skugptekiyo'] : 0; | |
| 706 | - $skusort = isset($_POST['sort']) ? $_POST['sort']: 0; | |
| 707 | - | |
| 708 | - $value['code'] = $skuname; | |
| 709 | - $value['name'] = $skudisp; | |
| 710 | - $value['cprice'] = $skucprice; | |
| 711 | - $value['price'] = $skuprice; | |
| 712 | - $value['unit'] = $skuunit; | |
| 713 | - $value['stocknum'] = $skuzaikonum; | |
| 714 | - $value['stock'] = $skuzaiko; | |
| 715 | - $value['gp'] = $skugptekiyo; | |
| 716 | - $value['sort'] = $skusort; | |
| 717 | - $value = $usces->stripslashes_deep_post($value); | |
| 718 | - | |
| 719 | - $skus = $usces->get_skus($post_ID); | |
| 720 | - foreach( $skus as $sku ){ | |
| 721 | - if( $sku['code'] == $skuname && $sku['meta_id'] != $skumetaid){ | |
| 722 | - return -1; | |
| 723 | - break; | |
| 724 | - } | |
| 725 | - } | |
| 726 | - | |
| 727 | - $value = apply_filters('usces_filter_up_item_sku_meta_value', $value); | |
| 728 | - | |
| 729 | - $valueserialized = serialize($value); | |
| 730 | - | |
| 731 | - if ( !WCUtils::is_blank($skumetaid) && !WCUtils::is_blank($skuname) && !WCUtils::is_blank($skuprice) ) { | |
| 732 | - | |
| 733 | - wp_cache_delete($post_ID, 'post_meta'); | |
| 734 | - | |
| 735 | - $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $skumetaid) ); | |
| 736 | - return $res; | |
| 737 | - } | |
| 738 | - return false; | |
| 739 | -} // update_meta | |
| 740 | - | |
| 741 | - | |
| 742 | - | |
| 743 | -/** | |
| 744 | - * del_item_option_meta | |
| 745 | - */ | |
| 746 | -function del_item_option_meta( $post_ID ) { | |
| 747 | - global $wpdb; | |
| 748 | - | |
| 749 | - $post_ID = (int) $post_ID; | |
| 750 | - $optmetaid = isset($_POST['optmetaid']) ? (int)$_POST['optmetaid'] : ''; | |
| 751 | - | |
| 752 | - wp_cache_delete($post_ID, 'post_meta'); | |
| 753 | - | |
| 754 | - $res = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $optmetaid) ); | |
| 755 | - | |
| 756 | - $opts = usces_get_opts($post_ID); | |
| 757 | - if( !empty($opts) ){ | |
| 758 | - $i = 0; | |
| 759 | - foreach( $opts as $opt ){ | |
| 760 | - $opt['sort'] = $i; | |
| 761 | - $meta_id = $opt['meta_id']; | |
| 762 | - unset($opt['meta_id']); | |
| 763 | - $serialized_values = serialize($opt); | |
| 764 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) ); | |
| 765 | - $i++; | |
| 766 | - } | |
| 767 | - } | |
| 768 | - return ; | |
| 769 | -} // delete_meta | |
| 770 | - | |
| 771 | -/** | |
| 772 | - * del_item_sku_meta | |
| 773 | - */ | |
| 774 | -function del_item_sku_meta( $post_ID ) { | |
| 775 | - global $wpdb, $usces; | |
| 776 | - | |
| 777 | - $post_ID = (int) $post_ID; | |
| 778 | - $skumetaid = isset($_POST['skumetaid']) ? (int)$_POST['skumetaid'] : ''; | |
| 779 | - | |
| 780 | - wp_cache_delete($post_ID, 'post_meta'); | |
| 781 | - | |
| 782 | - $res = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $skumetaid) ); | |
| 783 | - | |
| 784 | - $skus = $usces->get_skus($post_ID); | |
| 785 | - if( !empty($skus) ){ | |
| 786 | - $i = 0; | |
| 787 | - foreach( $skus as $sku ){ | |
| 788 | - $sku['sort'] = $i; | |
| 789 | - $meta_id = $sku['meta_id']; | |
| 790 | - unset($sku['meta_id']); | |
| 791 | - $serialized_values = serialize($sku); | |
| 792 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) ); | |
| 793 | - $i++; | |
| 794 | - } | |
| 795 | - } | |
| 796 | - return ; | |
| 797 | -} // delete_meta | |
| 798 | - | |
| 799 | - | |
| 800 | - | |
| 801 | -function select_common_option( $post_ID ) { | |
| 802 | - global $wpdb; | |
| 803 | - | |
| 804 | - $meta_id = isset($_POST['meta_id']) ? $_POST['meta_id'] : ''; | |
| 805 | - if(!$meta_id) return ; | |
| 806 | - | |
| 807 | - $meta_value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_id = %d ", $meta_id) ); | |
| 808 | - $array_val = unserialize( $meta_value ); | |
| 809 | - | |
| 810 | - $means = $array_val['means']; | |
| 811 | - $essential = $array_val['essential']; | |
| 812 | - $value = $array_val['value']; | |
| 813 | - $res = $means . '#usces#' . $essential . '#usces#' . $value; | |
| 814 | - return $res; | |
| 815 | -} // select_common_option | |
| 816 | - | |
| 817 | - | |
| 818 | - | |
| 819 | - | |
| 820 | -function order_item2cart_ajax(){ | |
| 821 | - global $usces; | |
| 822 | - | |
| 823 | - if( $_POST['action'] != 'order_item2cart_ajax' ) die(0); | |
| 824 | - | |
| 825 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 826 | - $order_id = usces_add_ordercartdata(); | |
| 827 | - if( !$order_id ) | |
| 828 | - die( 0 ); | |
| 829 | - | |
| 830 | - $cart = usces_get_ordercartdata( $order_id ); | |
| 831 | - $return = usces_get_ordercart_row( $order_id, $cart ); | |
| 832 | - /* | |
| 833 | - REGEX BUG: but it'll return info | |
| 834 | - Compose JavaScript for return | |
| 835 | - */ | |
| 836 | - die( $return ); | |
| 837 | -} | |
| 838 | - | |
| 839 | -function order_item_ajax(){ | |
| 840 | - global $usces; | |
| 841 | - | |
| 842 | - if( $_POST['action'] != 'order_item_ajax' ) die(0); | |
| 843 | - | |
| 844 | - $res = false; | |
| 845 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 846 | - | |
| 847 | - switch ( $_POST['mode'] ) { | |
| 848 | - case 'completionMail': | |
| 849 | - case 'orderConfirmMail': | |
| 850 | - case 'changeConfirmMail': | |
| 851 | - case 'receiptConfirmMail': | |
| 852 | - case 'mitumoriConfirmMail': | |
| 853 | - case 'cancelConfirmMail': | |
| 854 | - case 'otherConfirmMail': | |
| 855 | - $res = usces_order_confirm_message( $_POST['order_id'] ); | |
| 856 | - break; | |
| 857 | - case 'sendmail': | |
| 858 | - $res = usces_ajax_send_mail(); | |
| 859 | - break; | |
| 860 | - case 'get_order_item': | |
| 861 | - $res = get_order_item( $_POST['itemcode'] ); | |
| 862 | - break; | |
| 863 | - case 'get_item_select_option': | |
| 864 | - $res = usces_get_item_select_option( $_POST['cat_id'] ); | |
| 865 | - break; | |
| 866 | - case 'ordercheckpost': | |
| 867 | - $res = usces_update_ordercheck(); | |
| 868 | - break; | |
| 869 | - case 'getmember': | |
| 870 | - $res = usces_get_member_neworder(); | |
| 871 | - break; | |
| 872 | - case 'recalculation': | |
| 873 | - $res = usces_order_recalculation( $_POST['order_id'], $_POST['mem_id'], $_POST['post_ids'], $_POST['skus'], $_POST['prices'], $_POST['quants'], $_POST['upoint'], $_POST['shipping_charge'], $_POST['cod_fee'] ); | |
| 874 | - break; | |
| 875 | - } | |
| 876 | - | |
| 877 | - $res = apply_filters( 'usces_filter_order_item_ajax', $res ); | |
| 878 | - | |
| 879 | - if( $res === false ) die(0); | |
| 880 | - | |
| 881 | - //REGEX BUG: but it'll return info | |
| 882 | - // Compose JavaScript for return | |
| 883 | - die( $res ); | |
| 884 | -} | |
| 885 | - | |
| 886 | -function usces_get_item_select_option( $cat_id ){ | |
| 887 | - global $usces; | |
| 888 | - $number = apply_filters( 'usces_filter_item_select_numberposts', 50, $cat_id ); | |
| 889 | - $args = array( 'category' => $cat_id, 'numberposts' => $number ); | |
| 890 | - $items = get_posts( $args ); | |
| 891 | - $option = '<option value="-1">商品を選択して下さい</option>' . "\n"; | |
| 892 | - foreach( $items as $item ){ | |
| 893 | - $ItemName = get_post_meta($item->ID, '_itemName', true); | |
| 894 | - $ItemCode = get_post_meta($item->ID, '_itemCode', true); | |
| 895 | - $option .= '<option value="' . urlencode($ItemCode) . '">' . $ItemName . '(' . $ItemCode . ')' . '</option>' . "\n"; | |
| 896 | - } | |
| 897 | - return $option; | |
| 898 | -} | |
| 899 | - | |
| 900 | -/** | |
| 901 | - * order Item html | |
| 902 | - */ | |
| 903 | -function usces_get_member_neworder() { | |
| 904 | - global $wpdb; | |
| 905 | - $wpdb->show_errors(); | |
| 906 | - $res = ''; | |
| 907 | - $member_table = $wpdb->prefix . "usces_member"; | |
| 908 | - $query = $wpdb->prepare("SELECT * FROM $member_table WHERE mem_email = %s", trim($_POST['email'])); | |
| 909 | - $value = $wpdb->get_row( $query, ARRAY_A ); | |
| 910 | - if( !$value ){ | |
| 911 | - die( 'none#usces#1' ); | |
| 912 | - }else{ | |
| 913 | - $res .= 'ok#usces#member_id=' . $value['ID']; | |
| 914 | - $res .= '#usces#customer[name1]=' . $value['mem_name1']; | |
| 915 | - $res .= '#usces#customer[name2]=' . $value['mem_name2']; | |
| 916 | - $res .= '#usces#customer[name3]=' . $value['mem_name3']; | |
| 917 | - $res .= '#usces#customer[name4]=' . $value['mem_name4']; | |
| 918 | - $res .= '#usces#customer[zipcode]=' . $value['mem_zip']; | |
| 919 | - $res .= '#usces#customer[pref]=' . $value['mem_pref']; | |
| 920 | - $res .= '#usces#customer[address1]=' . $value['mem_address1']; | |
| 921 | - $res .= '#usces#customer[address2]=' . $value['mem_address2']; | |
| 922 | - $res .= '#usces#customer[address3]=' . $value['mem_address3']; | |
| 923 | - $res .= '#usces#customer[tel]=' . $value['mem_tel']; | |
| 924 | - $res .= '#usces#customer[fax]=' . $value['mem_fax']; | |
| 925 | - $res .= '#usces#delivery[name1]=' . $value['mem_name1']; | |
| 926 | - $res .= '#usces#delivery[name2]=' . $value['mem_name2']; | |
| 927 | - $res .= '#usces#delivery[name3]=' . $value['mem_name3']; | |
| 928 | - $res .= '#usces#delivery[name4]=' . $value['mem_name4']; | |
| 929 | - $res .= '#usces#delivery[zipcode]=' . $value['mem_zip']; | |
| 930 | - $res .= '#usces#delivery[pref]=' . $value['mem_pref']; | |
| 931 | - $res .= '#usces#delivery[address1]=' . $value['mem_address1']; | |
| 932 | - $res .= '#usces#delivery[address2]=' . $value['mem_address2']; | |
| 933 | - $res .= '#usces#delivery[address3]=' . $value['mem_address3']; | |
| 934 | - $res .= '#usces#delivery[tel]=' . $value['mem_tel']; | |
| 935 | - $res .= '#usces#delivery[fax]=' . $value['mem_fax']; | |
| 936 | - | |
| 937 | - $member_metetable = $wpdb->prefix . "usces_member_meta"; | |
| 938 | - $query = $wpdb->prepare("SELECT * FROM $member_metetable WHERE meta_key LIKE %s AND member_id = %d", 'csmb_%', $value['ID']); | |
| 939 | - $customs = $wpdb->get_results( $query, ARRAY_A ); | |
| 940 | - if( !empty($customs) ){ | |
| 941 | - foreach( $customs as $cusv ){ | |
| 942 | - $res .= '#usces#custom_customer[' . substr($cusv['meta_key'], 5) . ']=' . $cusv['meta_value']; | |
| 943 | - $res .= '#usces#custom_delivery[' . substr($cusv['meta_key'], 5) . ']=' . $cusv['meta_value']; | |
| 944 | - } | |
| 945 | - } | |
| 946 | - //die( urlencode($res) ); | |
| 947 | - } | |
| 948 | - | |
| 949 | - die( $res ); | |
| 950 | -} | |
| 951 | - | |
| 952 | -//function order_item2cart() { | |
| 953 | -// global $usces; | |
| 954 | -// | |
| 955 | -// if( $_POST['action'] != 'order_item2cart_ajax' ) die(0); | |
| 956 | -// | |
| 957 | -// usces_add_ordercartdata(); | |
| 958 | -// //$res = usces_update_ordercart(); | |
| 959 | -////20120613ysk start 0000500 | |
| 960 | -// //if( $res === false ) die(0); | |
| 961 | -// //if( $res === 0 ) die('nodata'); | |
| 962 | -// | |
| 963 | -// //die( $res ); | |
| 964 | -// return $res; | |
| 965 | -////20120613ysk end | |
| 966 | -//} | |
| 967 | - | |
| 968 | -function usces_add_ordercartdata(){ | |
| 969 | - global $usces, $wpdb; | |
| 970 | - $res = 0; | |
| 971 | - | |
| 972 | - $order_id = (int)$_POST['order_id']; | |
| 973 | - if( !$order_id ) | |
| 974 | - return $res; | |
| 975 | - | |
| 976 | - $post_id = (int)$_POST['post_id']; | |
| 977 | - $sku_code = urldecode($_POST['sku']); | |
| 978 | - $quantity = 1; | |
| 979 | - | |
| 980 | - $current_cart = usces_get_ordercartdata( $order_id ); | |
| 981 | - $temp_arr = array(); | |
| 982 | - foreach( $current_cart as $cv ){ | |
| 983 | - $temp_arr[] = $cv['row_index']; | |
| 984 | - } | |
| 985 | - $row_index = ( 0 < count($temp_arr) ) ? max($temp_arr) + 1 : 0; | |
| 986 | - | |
| 987 | - $cart_table = $wpdb->prefix . "usces_ordercart"; | |
| 988 | - $cart_meta_table = $wpdb->prefix . "usces_ordercart_meta"; | |
| 989 | - | |
| 990 | - $item_code = get_post_meta( $post_id, '_itemCode', true); | |
| 991 | - $item_name = get_post_meta( $post_id, '_itemName', true); | |
| 992 | - $skus = $usces->get_skus($post_id, 'code'); | |
| 993 | - $sku = $skus[$sku_code]; | |
| 994 | - if( empty($usces->option['tax_rate']) ){ | |
| 995 | - $tax = 0; | |
| 996 | - | |
| 997 | - }else{ | |
| 998 | - $tax = ($sku['price'] * $quantity) * $usces->options['tax_rate'] / 100; | |
| 999 | - $cr = $usces->options['system']['currency']; | |
| 1000 | - $decimal = $usces_settings['currency'][$cr][1]; | |
| 1001 | - $decipad = (int)str_pad( '1', $decimal+1, '0', STR_PAD_RIGHT ); | |
| 1002 | - switch( $usces->options['tax_method'] ){ | |
| 1003 | - case 'cutting': | |
| 1004 | - $tax = floor($tax*$decipad)/$decipad; | |
| 1005 | - break; | |
| 1006 | - case 'bring': | |
| 1007 | - $tax = ceil($tax*$decipad)/$decipad; | |
| 1008 | - break; | |
| 1009 | - case 'rounding': | |
| 1010 | - if( 0 < $decimal ){ | |
| 1011 | - $tax = round($tax, (int)$decimal); | |
| 1012 | - }else{ | |
| 1013 | - $tax = round($tax); | |
| 1014 | - } | |
| 1015 | - break; | |
| 1016 | - } | |
| 1017 | - } | |
| 1018 | - $query = $wpdb->prepare("INSERT INTO $cart_table | |
| 1019 | - ( | |
| 1020 | - order_id, row_index, post_id, item_code, item_name, | |
| 1021 | - sku_code, sku_name, cprice, price, quantity, | |
| 1022 | - unit, tax, destination_id, cart_serial | |
| 1023 | - ) VALUES ( | |
| 1024 | - %d, %d, %d, %s, %s, | |
| 1025 | - %s, %s, %f, %f, %d, | |
| 1026 | - %s, %d, %d, %s | |
| 1027 | - )", | |
| 1028 | - $order_id, $row_index, $post_id, $item_code, $item_name, | |
| 1029 | - $sku_code, $sku['name'], $sku['cprice'], $sku['price'], $quantity, | |
| 1030 | - $sku['unit'], $tax, NULL, NULL | |
| 1031 | - ); | |
| 1032 | - $res = $wpdb->query($query); | |
| 1033 | - $cart_id = NULL; | |
| 1034 | - if( false !== $res ){ | |
| 1035 | - $cart_id = $wpdb->insert_id ; | |
| 1036 | - | |
| 1037 | - $item_opts = usces_get_opts( $post_id, 'name' ); | |
| 1038 | - foreach( $item_opts as $key => $iopts ){ | |
| 1039 | - if( 3 == $iopts['means'] || 4 == $iopts['means'] ){ | |
| 1040 | - //POSTが無ければNULLで追加 | |
| 1041 | - if( !isset($_POST['itemOption'][$key]) ){ | |
| 1042 | - $query = $wpdb->prepare( | |
| 1043 | - "INSERT INTO $cart_meta_table | |
| 1044 | - ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )", | |
| 1045 | - $cart_id, 'option', $iopts['name'], NULL ); | |
| 1046 | - $wpdb->query( $query ); | |
| 1047 | - } | |
| 1048 | - } | |
| 1049 | - } | |
| 1050 | - | |
| 1051 | - if( isset($_POST['itemOption']) ){ | |
| 1052 | - foreach((array)$_POST['itemOption'] as $okey => $ovalue){ | |
| 1053 | - //$okey = urldecode($okey); | |
| 1054 | - $means = $item_opts[$okey]['means']; | |
| 1055 | - | |
| 1056 | - if(is_array($ovalue)) { | |
| 1057 | - $temp = array(); | |
| 1058 | - if( 4 == $means ){ | |
| 1059 | - foreach( $ovalue as $k => $v ){ | |
| 1060 | - //$temp[] = urldecode($v); | |
| 1061 | - $temp[] = $v; | |
| 1062 | - } | |
| 1063 | - }else{ | |
| 1064 | - foreach( $ovalue as $k => $v ){ | |
| 1065 | - //$temp[urlencode($k)] = $v; | |
| 1066 | - $temp[urlencode($k)] = $v; | |
| 1067 | - } | |
| 1068 | - } | |
| 1069 | - $ovalue = serialize($temp); | |
| 1070 | - } else { | |
| 1071 | - //$ovalue = urldecode($ovalue); | |
| 1072 | - $ovalue = $ovalue; | |
| 1073 | - } | |
| 1074 | - $aquery = $wpdb->prepare( | |
| 1075 | - "INSERT INTO $cart_meta_table | |
| 1076 | - ( cart_id, meta_type, meta_key, meta_value ) VALUES (%d, %s, %s, %s)", | |
| 1077 | - $cart_id, 'option', $okey, $ovalue ); | |
| 1078 | - $wpdb->query($aquery); | |
| 1079 | - } | |
| 1080 | - } | |
| 1081 | - } | |
| 1082 | - | |
| 1083 | - $res = apply_filters( 'usces_filter_add_ordercart', $res, $order_id, $cart_id ); | |
| 1084 | - | |
| 1085 | - if( $res ) | |
| 1086 | - return $order_id; | |
| 1087 | - else | |
| 1088 | - return $res; | |
| 1089 | -} | |
| 1090 | - | |
| 1091 | -function get_order_item( $item_code ) { | |
| 1092 | - global $usces, $post; | |
| 1093 | - | |
| 1094 | - $post_id = $usces->get_postIDbyCode( $item_code ); | |
| 1095 | - if( $post_id == NULL ) return false; | |
| 1096 | - $post = get_post($post_id); | |
| 1097 | - | |
| 1098 | - $pict_id = $usces->get_mainpictid( $item_code ); | |
| 1099 | - $pict_link = wp_get_attachment_image($pict_id, array(150, 150), true); | |
| 1100 | - preg_match("/^\<a .+\>(\<img .+\/\>)\<\/a\>$/", $pict_link, $match); | |
| 1101 | - $pict = isset($match[1]) ? $match[1] : ''; | |
| 1102 | - $skus = $usces->get_skus( $post_id ); | |
| 1103 | - $optkeys = $usces->get_itemOptionKey( $post_id ); | |
| 1104 | - $itemName = esc_html($usces->getItemName($post_id)); | |
| 1105 | - | |
| 1106 | - $r = ''; | |
| 1107 | - $r .= $pict_link . "\n"; | |
| 1108 | - $r .= "<h3>" . $itemName . "</h3>\n"; | |
| 1109 | - $r .= "<div class='skuform'>\n"; | |
| 1110 | - | |
| 1111 | - $r .= "<table class='skumulti'>\n"; | |
| 1112 | - $r .= "<thead>\n"; | |
| 1113 | - $r .= "<tr>\n"; | |
| 1114 | - $r .= "<th>" . __('SKU code','usces') . "</th>\n"; | |
| 1115 | - $r .= "<th>" . __('SKU display name ','usces') . "</th>\n"; | |
| 1116 | - $usces_listprice = __('List price', 'usces') . usces_guid_tax('return'); | |
| 1117 | - $r .= "<th>" . apply_filters('usces_filter_listprice_label', $usces_listprice, __('List price', 'usces'), usces_guid_tax('return')) . "</th>\n"; | |
| 1118 | - $usces_sellingprice = __('Sale price','usces') . usces_guid_tax('return'); | |
| 1119 | - $r .= "<th>" . apply_filters('usces_filter_sellingprice_label', $usces_sellingprice, __('Sale price', 'usces'), usces_guid_tax('return')) . "</th>\n"; | |
| 1120 | - $r .= "<th>" . __('stock status','usces') . "</th>\n"; | |
| 1121 | - $r .= "<th>" . __('stock','usces') . "</th>\n"; | |
| 1122 | - $r .= "<th>" . __('unit','usces') . "</th>\n"; | |
| 1123 | - $r .= "<th> </th>\n"; | |
| 1124 | - $r .= "</tr>\n"; | |
| 1125 | - $r .= "</thead>\n"; | |
| 1126 | - $r .= "<tbody>\n"; | |
| 1127 | - //for ($i=0; $i<count($skus['code']); $i++) : | |
| 1128 | - // $sku = esc_attr($skus['code'][$i]); | |
| 1129 | - // $cprice = esc_attr($skus['cprice'][$i]); | |
| 1130 | - // $price = esc_attr($skus['price'][$i]); | |
| 1131 | - // $zaiko = esc_attr($usces->zaiko_status[$skus['stock'][$i]]); | |
| 1132 | - // $zaikonum = esc_attr($skus['stocknum'][$i]); | |
| 1133 | - // $disp = esc_attr($skus['name'][$i]); | |
| 1134 | - // $unit = esc_attr($skus['unit'][$i]); | |
| 1135 | - // $gptekiyo = $skus['gp'][$i]; | |
| 1136 | - foreach($skus as $sku) : | |
| 1137 | - $key = urlencode($sku['code']); | |
| 1138 | - $cprice = esc_attr($sku['cprice']); | |
| 1139 | - $price = esc_attr($sku['price']); | |
| 1140 | - $zaiko = esc_attr($usces->zaiko_status[$sku['stock']]); | |
| 1141 | - $zaikonum = esc_attr($sku['stocknum']); | |
| 1142 | - $disp = esc_attr($sku['name']); | |
| 1143 | - $unit = esc_attr($sku['unit']); | |
| 1144 | - $gptekiyo = $sku['gp']; | |
| 1145 | - $sort = (int)$sku['sort']; | |
| 1146 | - $r .= "<tr>\n"; | |
| 1147 | - $r .= "<td rowspan='2'>" . esc_js($sku['code']) . "</td>\n"; | |
| 1148 | - $r .= "<td>" . $disp . "</td>\n"; | |
| 1149 | - $r .= "<td><span class='cprice'>" . ( ( !empty($cprice) ) ? usces_crform( $cprice, true, false, 'return' ) : '' ) . "</span></td>\n"; | |
| 1150 | - $r .= "<td><span class='price'>" . usces_crform( $price, true, false, 'return' ) . "</span></td>\n"; | |
| 1151 | - $r .= "<td>" . $zaiko . "</td>\n"; | |
| 1152 | - $r .= "<td>" . $zaikonum . "</td>\n"; | |
| 1153 | -// $r .= "<td>" . usces_the_itemQuant() . "</td>\n"; | |
| 1154 | - $r .= "<td>" . $unit . "</td>\n"; | |
| 1155 | - $r .= "<td>\n"; | |
| 1156 | - $r .= "<input name=\"itemNEWName[{$post_id}][{$key}]\" type=\"hidden\" id=\"itemNEWName[{$post_id}][{$key}]\" value=\"{$itemName}\" />\n"; | |
| 1157 | - $r .= "<input name=\"itemNEWCode[{$post_id}][{$key}]\" type=\"hidden\" id=\"itemNEWCode[{$post_id}][{$key}]\" value=\"{$item_code}\" />\n"; | |
| 1158 | - $r .= "<input name=\"skuNEWName[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWName[{$post_id}][{$key}]\" value=\"{$key}\" />\n"; | |
| 1159 | - $r .= "<input name=\"skuNEWCprice[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWCprice[{$post_id}][{$key}]\" value=\"{$cprice}\" />\n"; | |
| 1160 | - $r .= "<input name=\"skuNEWDisp[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWDisp[{$post_id}][{$key}]\" value=\"{$disp}\" />\n"; | |
| 1161 | - $r .= "<input name=\"zaikoNEWnum[{$post_id}][{$key}]\" type=\"hidden\" id=\"zaikoNEWnum[{$post_id}][{$key}]\" value=\"{$zaikonum}\" />\n"; | |
| 1162 | - $r .= "<input name=\"zaiNEWko[{$post_id}][{$key}]\" type=\"hidden\" id=\"zaiNEWko[{$post_id}][{$key}]\" value=\"{$zaiko}\" />\n"; | |
| 1163 | - $r .= "<input name=\"uniNEWt[{$post_id}][{$key}]\" type=\"hidden\" id=\"uniNEWt[{$post_id}][{$key}]\" value=\"{$unit}\" />\n"; | |
| 1164 | - $r .= "<input name=\"gpNEWtekiyo[{$post_id}][{$key}]\" type=\"hidden\" id=\"gpNEWtekiyo[{$post_id}][{$key}]\" value=\"{$gptekiyo}\" />\n"; | |
| 1165 | - $r .= "<input name=\"skuNEWPrice[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWPrice[{$post_id}][{$key}]\" value=\"{$price}\" />\n"; | |
| 1166 | - $r .= "<input name=\"inNEWCart[{$post_id}][{$key}]\" type=\"button\" id=\"inNEWCart[{$post_id}][{$key}]\" class=\"skubutton\" value=\"" . __('Add to Whish List','usces') . "\" onclick=\"orderItem.add2cart('{$post_id}', '{$key}');\" />"; | |
| 1167 | - $r .= "</td>\n"; | |
| 1168 | - $r .= "</tr>\n"; | |
| 1169 | - $r .= "<tr>\n"; | |
| 1170 | - if($optkeys) : | |
| 1171 | - $r .= "<td colspan='7'>\n"; | |
| 1172 | - foreach($optkeys as $optkey => $optvalue) : | |
| 1173 | - $r .= "<div>\n"; | |
| 1174 | - $name = esc_attr($optvalue); | |
| 1175 | - $optcode = urlencode($name); | |
| 1176 | - $opts = usces_get_opts($post_id, 'name'); | |
| 1177 | - $opt = $opts[$optvalue]; | |
| 1178 | -//20110715ysk start 0000202 | |
| 1179 | - $means = (int)$opt['means']; | |
| 1180 | - $essential = (int)$opt['essential']; | |
| 1181 | - $r .= "\n<label for='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_label'>{$name}</label>\n"; | |
| 1182 | - switch($means) { | |
| 1183 | - case 0://Single-select | |
| 1184 | - case 1://Multi-select | |
| 1185 | - $selects = explode("\n", $opt['value']); | |
| 1186 | - $multiple = ($means === 0) ? '' : ' multiple'; | |
| 1187 | - $multiple_array = ($means === 0) ? '' : '_multiple'; | |
| 1188 | - | |
| 1189 | - $r .= "\n<select name='itemNEWOption[{$post_id}][{$key}][{$optcode}]' id='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_select{$multiple_array}'{$multiple}>\n"; | |
| 1190 | - if($essential == 1) | |
| 1191 | - $r .= "\t<option value='#NONE#' selected='selected'>" . __('Choose','usces') . "</option>\n"; | |
| 1192 | - $s=0; | |
| 1193 | - foreach($selects as $v) { | |
| 1194 | - $v = trim($v); | |
| 1195 | - //$optvalue = urlencode($v); | |
| 1196 | - if($s == 0 && $essential == 0) | |
| 1197 | - $selected = ' selected="selected"'; | |
| 1198 | - else | |
| 1199 | - $selected = ''; | |
| 1200 | - $r .= "\t<option value='{$v}'{$selected}>{$v}</option>\n"; | |
| 1201 | - $s++; | |
| 1202 | - } | |
| 1203 | - $r .= "</select>\n"; | |
| 1204 | - break; | |
| 1205 | - case 2://Text | |
| 1206 | - $r .= "\n<input name='itemNEWOption[{$post_id}][{$key}][{$optcode}]' type='text' id='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"\" />\n"; | |
| 1207 | - break; | |
| 1208 | - case 3://Radio-button | |
| 1209 | - $selects = explode("\n", $opt['value']); | |
| 1210 | - | |
| 1211 | - $i=0; | |
| 1212 | - foreach($selects as $v) { | |
| 1213 | - $r .= '<label for="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_radio_label"><input name="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']" type="radio" id="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_radio" value="' . urlencode($v) . '">' . esc_html($v) . "</label>\n"; | |
| 1214 | - $i++; | |
| 1215 | - } | |
| 1216 | - break; | |
| 1217 | - case 4://Check-box | |
| 1218 | - $selects = explode("\n", $opt['value']); | |
| 1219 | - | |
| 1220 | - $i=0; | |
| 1221 | - foreach($selects as $v) { | |
| 1222 | - $r .= '<label for="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_checkbox_label"><input name="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']" type="checkbox" id="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_checkbox" value="' . urlencode($v) . '">' . esc_html($v) . "</label>\n"; | |
| 1223 | - $i++; | |
| 1224 | - } | |
| 1225 | - break; | |
| 1226 | - case 5://Text-area | |
| 1227 | - $r .= "\n<textarea name='itemNEWOption[{$post_id}][{$key}][{$optcode}]' id='itemNEWOption[{$post_id}][{$key}][{$optcode}]' class='iopt_textarea'></textarea>\n"; | |
| 1228 | - break; | |
| 1229 | - } | |
| 1230 | -//20110715ysk end | |
| 1231 | - $r .= "<input name=\"optNEWCode[{$post_id}][{$key}][{$optcode}]\" type=\"hidden\" id=\"optNEWCode[{$post_id}][{$key}][{$optcode}]\" value=\"{$optcode}\" />\n"; | |
| 1232 | - $r .= "<input name=\"optNEWEssential[{$post_id}][{$key}][{$optcode}]\" type=\"hidden\" id=\"optNEWEssential[{$post_id}][{$key}][{$optcode}]\" value=\"{$essential}\" />\n"; | |
| 1233 | - $r .= "</div>\n"; | |
| 1234 | - endforeach; | |
| 1235 | - $r .= "</td>\n"; | |
| 1236 | - endif; | |
| 1237 | - $r .= "</tr>\n"; | |
| 1238 | - //endfor; | |
| 1239 | - endforeach; | |
| 1240 | - $r .= "</tbody>\n"; | |
| 1241 | - $r .= "</table>\n"; | |
| 1242 | - | |
| 1243 | - | |
| 1244 | - $r .= "</div>\n"; | |
| 1245 | - | |
| 1246 | - return $r; | |
| 1247 | -} | |
| 1248 | - | |
| 1249 | -function item_option_ajax() | |
| 1250 | -{ | |
| 1251 | - | |
| 1252 | - if( $_POST['action'] != 'item_option_ajax' ) die(0); | |
| 1253 | - | |
| 1254 | - if(isset($_POST['update'])){ | |
| 1255 | - $id = up_item_option_meta( $_POST['ID'] ); | |
| 1256 | - | |
| 1257 | - }else if(isset($_POST['delete'])){ | |
| 1258 | - $id = del_item_option_meta( $_POST['ID'] ); | |
| 1259 | - | |
| 1260 | - }else if(isset($_POST['select'])){ | |
| 1261 | - $res = select_common_option( $_POST['ID'] ); | |
| 1262 | - die( $res ); | |
| 1263 | - | |
| 1264 | - }else if(isset($_POST['sort'])){ | |
| 1265 | - $id = usces_sort_post_meta( $_POST['ID'], $_POST['meta'] ); | |
| 1266 | - //die( $res ); | |
| 1267 | - | |
| 1268 | - }else{ | |
| 1269 | - $id = add_item_option_meta( $_POST['ID'] ); | |
| 1270 | - | |
| 1271 | - } | |
| 1272 | - | |
| 1273 | - $opts = usces_get_opts( $_POST['ID'] ); | |
| 1274 | - | |
| 1275 | - $r = ''; | |
| 1276 | - foreach ( $opts as $opt ) | |
| 1277 | - $r .= _list_item_option_meta_row( $opt ); | |
| 1278 | - | |
| 1279 | - $res = $r . '#usces#' . $id; | |
| 1280 | - //REGEX BUG: but it'll return info | |
| 1281 | - // Compose JavaScript for return | |
| 1282 | - die( $res ); | |
| 1283 | -} | |
| 1284 | - | |
| 1285 | -function item_sku_ajax(){ | |
| 1286 | - global $usces; | |
| 1287 | - | |
| 1288 | - $id = ''; | |
| 1289 | - if( $_POST['action'] != 'item_sku_ajax' ) die(0); | |
| 1290 | - | |
| 1291 | - if(isset($_POST['update'])){ | |
| 1292 | - $id = up_item_sku_meta( $_POST['ID'] ); | |
| 1293 | - | |
| 1294 | - }else if(isset($_POST['delete'])){ | |
| 1295 | - $id = del_item_sku_meta( $_POST['ID'] ); | |
| 1296 | - | |
| 1297 | - }else if(isset($_POST['select'])){ | |
| 1298 | - $res = select_item_sku( $_POST['ID'] ); | |
| 1299 | - die( $res ); | |
| 1300 | - | |
| 1301 | - }else if(isset($_POST['sort'])){ | |
| 1302 | - $id = usces_sort_post_meta( $_POST['ID'], $_POST['meta'] ); | |
| 1303 | - //die( $res ); | |
| 1304 | - | |
| 1305 | - }else{ | |
| 1306 | - $id = add_item_sku_meta( $_POST['ID'] ); | |
| 1307 | - | |
| 1308 | - } | |
| 1309 | - | |
| 1310 | - $skus = $usces->get_skus( $_POST['ID'] ); | |
| 1311 | - | |
| 1312 | - $r = ''; | |
| 1313 | - | |
| 1314 | - foreach ( (array)$skus as $sku ) | |
| 1315 | - $r .= _list_item_sku_meta_row( $sku ); | |
| 1316 | - | |
| 1317 | - //$list = has_item_sku_list(); | |
| 1318 | - | |
| 1319 | - $res = $r . '#usces#' . $id; | |
| 1320 | - | |
| 1321 | - die( $res ); | |
| 1322 | -} | |
| 1323 | - | |
| 1324 | -function item_save_metadata( $post_id, $post ) { | |
| 1325 | - global $usces, $wpdb; | |
| 1326 | - | |
| 1327 | - $message = ''; | |
| 1328 | - | |
| 1329 | -// usces_log('item_save_metadata : '.print_r($post_id,true), 'acting_transaction.log'); | |
| 1330 | -// usces_log('item_save_metadata : '.print_r($_POST['post_ID'],true), 'acting_transaction.log'); | |
| 1331 | - // パーミッションチェック | |
| 1332 | - if ( isset($_POST['page']) && 'usces_itemedit' == $_POST['page']) { | |
| 1333 | - if ( !current_user_can( 'edit_post', $post_id ) ){ | |
| 1334 | - $usces->set_action_status('error', 'ERROR : '.__('Sorry, you do not have the right to edit this post.')); | |
| 1335 | - return $post_id; | |
| 1336 | - } | |
| 1337 | - } else { | |
| 1338 | - return $post_id; | |
| 1339 | - } | |
| 1340 | - | |
| 1341 | - if ( !wp_verify_nonce( $_POST['usces_nonce'], 'usc-e-shop' )) { | |
| 1342 | - return $post_id; | |
| 1343 | - } | |
| 1344 | - | |
| 1345 | -// $post_id = $_POST['post_ID']; | |
| 1346 | -// if( $post_id < 0 ){ | |
| 1347 | -// return $post_id; | |
| 1348 | -// } | |
| 1349 | - | |
| 1350 | - | |
| 1351 | - | |
| 1352 | - // 自動保存ルーチンかどうかチェック。そうだった場合はフォームを送信しない(何もしない) | |
| 1353 | - if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) | |
| 1354 | - return $post_id; | |
| 1355 | - | |
| 1356 | - $usces->set_item_mime($post_id, 'item'); | |
| 1357 | - | |
| 1358 | - $itemCode = trim($_POST['itemCode' ]); | |
| 1359 | - if( preg_match('/[^0-9a-zA-Z\-_]/', $itemCode) ){ | |
| 1360 | -// $itemCode = ''; | |
| 1361 | -// $usces->action_message = '商品コードは半角英数(-_を含む)で入力して下さい。' . "<br />"; | |
| 1362 | - } | |
| 1363 | - if( empty($itemCode) ){ | |
| 1364 | - $itemCode = ''; | |
| 1365 | - $message .= __('Product code has not been entered.', 'usces') . "<br />"; | |
| 1366 | - }elseif( $res = usces_is_same_itemcode($post->ID, $itemCode)) { | |
| 1367 | - $message .= 'post_ID '; | |
| 1368 | - foreach( $res as $postid ) | |
| 1369 | - $message .= $postid . ', '; | |
| 1370 | - $message .= 'Same product code is registered here.' . "<br />"; | |
| 1371 | - $usces->set_action_status('error', 'ERROR : '.$message); | |
| 1372 | - } | |
| 1373 | - update_post_meta($post_id, '_itemCode', $itemCode); | |
| 1374 | - | |
| 1375 | - | |
| 1376 | - if(isset($_POST['itemName'])){ | |
| 1377 | - $itemName = trim($_POST['itemName']); | |
| 1378 | - update_post_meta($post_id, '_itemName', $itemName); | |
| 1379 | - } | |
| 1380 | -// if(isset($_POST['itemCode'])){ | |
| 1381 | -// $itemCode = trim($_POST['itemCode']); | |
| 1382 | -// update_post_meta($post_id, '_itemCode', $itemCode); | |
| 1383 | -// } | |
| 1384 | - if(isset($_POST['itemRestriction'])){ | |
| 1385 | - $itemRestriction = trim($_POST['itemRestriction']); | |
| 1386 | - update_post_meta($post_id, '_itemRestriction', $itemRestriction); | |
| 1387 | - } | |
| 1388 | - if(isset($_POST['itemPointrate'])){ | |
| 1389 | - $itemPointrate = (int)$_POST['itemPointrate']; | |
| 1390 | - update_post_meta($post_id, '_itemPointrate', $itemPointrate); | |
| 1391 | - } | |
| 1392 | - if(isset($_POST['itemGpNum1'])){ | |
| 1393 | - $itemGpNum1 = (int)$_POST['itemGpNum1']; | |
| 1394 | - update_post_meta($post_id, '_itemGpNum1', $itemGpNum1); | |
| 1395 | - } | |
| 1396 | - if(isset($_POST['itemGpNum2'])){ | |
| 1397 | - $itemGpNum2 = (int)$_POST['itemGpNum2']; | |
| 1398 | - update_post_meta($post_id, '_itemGpNum2', $itemGpNum2); | |
| 1399 | - } | |
| 1400 | - if(isset($_POST['itemGpNum3'])){ | |
| 1401 | - $itemGpNum3 = (int)$_POST['itemGpNum3']; | |
| 1402 | - update_post_meta($post_id, '_itemGpNum3', $itemGpNum3); | |
| 1403 | - } | |
| 1404 | - if(isset($_POST['itemGpDis1'])){ | |
| 1405 | - $itemGpDis1 = (int)$_POST['itemGpDis1']; | |
| 1406 | - update_post_meta($post_id, '_itemGpDis1', $itemGpDis1); | |
| 1407 | - } | |
| 1408 | - if(isset($_POST['itemGpDis2'])){ | |
| 1409 | - $itemGpDis2 = (int)$_POST['itemGpDis2']; | |
| 1410 | - update_post_meta($post_id, '_itemGpDis2', $itemGpDis2); | |
| 1411 | - } | |
| 1412 | - if(isset($_POST['itemGpDis3'])){ | |
| 1413 | - $itemGpDis3 = (int)$_POST['itemGpDis3']; | |
| 1414 | - update_post_meta($post_id, '_itemGpDis3', $itemGpDis3); | |
| 1415 | - } | |
| 1416 | - | |
| 1417 | - if(isset($_POST['itemShipping'])){ | |
| 1418 | - $itemShipping = (int)$_POST['itemShipping']; | |
| 1419 | - update_post_meta($post_id, '_itemShipping', $itemShipping); | |
| 1420 | - } | |
| 1421 | - if(isset($_POST['itemDeliveryMethod'])){ | |
| 1422 | - $itemDeliveryMethod = array(); | |
| 1423 | - foreach( (array)$_POST["itemDeliveryMethod"] as $dmid){ | |
| 1424 | - $itemDeliveryMethod[] = $dmid; | |
| 1425 | - } | |
| 1426 | - update_post_meta($post_id, '_itemDeliveryMethod', $itemDeliveryMethod); | |
| 1427 | - } | |
| 1428 | - if(isset($_POST['itemShippingCharge'])){ | |
| 1429 | - $itemShippingCharge = (int)$_POST['itemShippingCharge']; | |
| 1430 | - update_post_meta($post_id, '_itemShippingCharge', $itemShippingCharge); | |
| 1431 | - } | |
| 1432 | - $itemIndividualSCharge = isset($_POST['itemIndividualSCharge']) ? 1 : 0; | |
| 1433 | - update_post_meta($post_id, '_itemIndividualSCharge', $itemIndividualSCharge); | |
| 1434 | - | |
| 1435 | - if(isset($_POST['wcexp'])){ | |
| 1436 | - $wcexp = serialize($_POST['wcexp']); | |
| 1437 | - update_post_meta($post_id, '_wcexp', $wcexp); | |
| 1438 | - } | |
| 1439 | - | |
| 1440 | - //SKU | |
| 1441 | - if( isset($_POST['itemsku']) ){ | |
| 1442 | - $meta_ids = array(); | |
| 1443 | - $codes = array(); | |
| 1444 | - $uniq_code = false; | |
| 1445 | - $irreg_code = false; | |
| 1446 | - $irreg_price = false; | |
| 1447 | - | |
| 1448 | - foreach($_POST['itemsku'] as $mid => $temp){ | |
| 1449 | - $meta_ids[] = $mid; | |
| 1450 | - } | |
| 1451 | - $meta_ids = array_unique($meta_ids); | |
| 1452 | - foreach( $meta_ids as $meta_id ){ | |
| 1453 | - | |
| 1454 | - $skucode = isset($_POST['itemsku'][$meta_id]['key']) ? trim( $_POST['itemsku'][$meta_id]['key'] ) : ''; | |
| 1455 | - $skucprice = isset($_POST['itemsku'][$meta_id]['cprice']) ? trim( $_POST['itemsku'][$meta_id]['cprice'] ): 0; | |
| 1456 | - $skuprice = isset($_POST['itemsku'][$meta_id]['price']) ? trim( $_POST['itemsku'][$meta_id]['price'] ): 0; | |
| 1457 | - $skustocknum = isset($_POST['itemsku'][$meta_id]['zaikonum']) ? trim( $_POST['itemsku'][$meta_id]['zaikonum'] ): 0; | |
| 1458 | - $skustock = isset($_POST['itemsku'][$meta_id]['zaiko']) ? (int)$_POST['itemsku'][$meta_id]['zaiko'] : ''; | |
| 1459 | - $skuname = isset($_POST['itemsku'][$meta_id]['skudisp']) ? trim( $_POST['itemsku'][$meta_id]['skudisp'] ): ''; | |
| 1460 | - $skuunit = isset($_POST['itemsku'][$meta_id]['skuunit']) ? trim( $_POST['itemsku'][$meta_id]['skuunit'] ): ''; | |
| 1461 | - $skugp = isset($_POST['itemsku'][$meta_id]['skugptekiyo']) ? (int)$_POST['itemsku'][$meta_id]['skugptekiyo'] : 0; | |
| 1462 | - $skusort = isset($_POST['itemsku'][$meta_id]['sort']) ? $_POST['itemsku'][$meta_id]['sort']: 0; | |
| 1463 | - | |
| 1464 | - $skus['code'] = $skucode; | |
| 1465 | - $skus['name'] = $skuname; | |
| 1466 | - $skus['cprice'] = $skucprice; | |
| 1467 | - $skus['price'] = $skuprice; | |
| 1468 | - $skus['unit'] = $skuunit; | |
| 1469 | - $skus['stocknum'] = $skustocknum; | |
| 1470 | - $skus['stock'] = $skustock; | |
| 1471 | - $skus['gp'] = $skugp; | |
| 1472 | - $skus['sort'] = $skusort; | |
| 1473 | - $skus = $usces->stripslashes_deep_post($skus); | |
| 1474 | - $skus = apply_filters( 'usces_filter_item_save_sku_metadata', $skus, $meta_id ); | |
| 1475 | - | |
| 1476 | - $valueserialized = serialize($skus); | |
| 1477 | - $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $meta_id) ); | |
| 1478 | - | |
| 1479 | - if( in_array( $skucode, $codes ) ) | |
| 1480 | - $uniq_code = true; | |
| 1481 | - | |
| 1482 | - if( WCUtils::is_blank($skucode) ) | |
| 1483 | - $irreg_code = true; | |
| 1484 | - | |
| 1485 | - if( WCUtils::is_blank($skuprice) || preg_match('/[^0-9.]/', $skuprice) || 1 < substr_count($skuprice, '.' ) ) | |
| 1486 | - $irreg_price = true; | |
| 1487 | - | |
| 1488 | - $codes[] = $skucode; | |
| 1489 | - } | |
| 1490 | - | |
| 1491 | - if( $uniq_code ){ | |
| 1492 | - $message .= __('SKU code is duplicated.','usces') . "<br />"; | |
| 1493 | - } | |
| 1494 | - if( $irreg_code ){ | |
| 1495 | - $message .= __('SKU code is invalid.','usces') . "<br />"; | |
| 1496 | - } | |
| 1497 | - if( $irreg_price ){ | |
| 1498 | - $message .= __('SKU of invalid selling price exists.','usces') . "<br />"; | |
| 1499 | - } | |
| 1500 | - } | |
| 1501 | - //OPT | |
| 1502 | - if( isset($_POST['itemopt']) ){ | |
| 1503 | - $meta_ids = array(); | |
| 1504 | - $names = array(); | |
| 1505 | - $uniq_name = false; | |
| 1506 | - $irreg_name = false; | |
| 1507 | - $irreg_value = false; | |
| 1508 | - | |
| 1509 | - foreach($_POST['itemopt'] as $mid => $temp){ | |
| 1510 | - $meta_ids[] = $mid; | |
| 1511 | - } | |
| 1512 | - $meta_ids = array_unique($meta_ids); | |
| 1513 | - foreach( $meta_ids as $meta_id ){ | |
| 1514 | - | |
| 1515 | - $optname = isset($_POST['itemopt'][$meta_id]['name']) ? $_POST['itemopt'][$meta_id]['name'] : ''; | |
| 1516 | - $optmeans = isset($_POST['itemopt'][$meta_id]['means']) ? (int)$_POST['itemopt'][$meta_id]['means']: 0; | |
| 1517 | - $optessential = isset($_POST['itemopt'][$meta_id]['essential']) ? $_POST['itemopt'][$meta_id]['essential']: 0; | |
| 1518 | - $optsort = isset($_POST['itemopt'][$meta_id]['sort']) ? $_POST['itemopt'][$meta_id]['sort']: 0; | |
| 1519 | - $optvalue = isset($_POST['itemopt'][$meta_id]['value']) ? trim($_POST['itemopt'][$meta_id]['value']) : ''; | |
| 1520 | - | |
| 1521 | - $opts['name'] = str_replace("\\",'',$optname); | |
| 1522 | - $opts['value'] = str_replace("\\",'',$optvalue); | |
| 1523 | - $opts['means'] = $optmeans; | |
| 1524 | - $opts['essential'] = $optessential; | |
| 1525 | - $opts['sort'] = $optsort; | |
| 1526 | - $opts = $usces->stripslashes_deep_post($opts); | |
| 1527 | - | |
| 1528 | - $valueserialized = serialize($opts); | |
| 1529 | - $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $valueserialized, $meta_id) ); | |
| 1530 | - | |
| 1531 | - if( in_array( $optname, $names ) ) | |
| 1532 | - $uniq_name = true; | |
| 1533 | - | |
| 1534 | - if( WCUtils::is_blank($optname) ) | |
| 1535 | - $irreg_name = true; | |
| 1536 | - | |
| 1537 | - if( WCUtils::is_blank($optvalue) && 1 >= $optmeans ) | |
| 1538 | - $irreg_value = true; | |
| 1539 | - | |
| 1540 | - $names[] = $optname; | |
| 1541 | - } | |
| 1542 | - | |
| 1543 | - | |
| 1544 | - if( $uniq_name ){ | |
| 1545 | - $message .= __("Commodity option option name duplicates exist.", "usces") . "<br />"; | |
| 1546 | - } | |
| 1547 | - if( $irreg_name ){ | |
| 1548 | - $message .= __("Commodity option not entered there is the option name.", "usces") . "<br />"; | |
| 1549 | - } | |
| 1550 | - if( $irreg_value ){ | |
| 1551 | - $message .= __("If you select 'single select' and 'multi-select' the trade option, please enter the select value.", "usces") . "<br />"; | |
| 1552 | - } | |
| 1553 | - } | |
| 1554 | - | |
| 1555 | - do_action('usces_action_save_product', $post_id, $post); | |
| 1556 | - $message = apply_filters( 'usces_filter_save_product_message', $message, $post_id ); | |
| 1557 | - | |
| 1558 | -// $usces->action_status = 'none'; | |
| 1559 | -// $usces->action_message = ''; | |
| 1560 | - if( $message ){ | |
| 1561 | - $usces->set_action_status('error', 'ERROR : '.$message); | |
| 1562 | - }else{ | |
| 1563 | - $usces->set_action_status('success', __('Registration of the product is complete.','usces')); | |
| 1564 | - } | |
| 1565 | - | |
| 1566 | - wp_cache_delete($post_id, 'post_meta'); | |
| 1567 | -} | |
| 1568 | - | |
| 1569 | -function usces_link_replace($para) { | |
| 1570 | - //$str = 'admin.php?page=' . USCES_PLUGIN_BASENAME . '&'; | |
| 1571 | - $str = 'admin.php?page=usces_itemedit&'; | |
| 1572 | - $url = preg_replace('|post\.php\?|i', $str, $para); | |
| 1573 | - return $url; | |
| 1574 | - | |
| 1575 | -} | |
| 1576 | - | |
| 1577 | -function usces_count_posts( $type = 'post', $perm = '' ) { | |
| 1578 | - global $wpdb; | |
| 1579 | - | |
| 1580 | - $user = wp_get_current_user(); | |
| 1581 | - | |
| 1582 | - $cache_key = $type; | |
| 1583 | - | |
| 1584 | - $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_mime_type = 'item'"; | |
| 1585 | - //$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; | |
| 1586 | - if ( 'readable' == $perm && is_user_logged_in() ) { | |
| 1587 | - if ( !current_user_can("read_private_{$type}s") ) { | |
| 1588 | - $cache_key .= '_' . $perm . '_' . $user->ID; | |
| 1589 | - $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; | |
| 1590 | - } | |
| 1591 | - } | |
| 1592 | - $query .= ' GROUP BY post_status'; | |
| 1593 | - | |
| 1594 | - $count = wp_cache_get($cache_key, 'counts'); | |
| 1595 | - if ( false !== $count ) | |
| 1596 | - // return $count; | |
| 1597 | - | |
| 1598 | - $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); | |
| 1599 | - | |
| 1600 | - $stats = array( ); | |
| 1601 | - foreach( (array) $count as $row_num => $row ) { | |
| 1602 | - $stats[$row['post_status']] = $row['num_posts']; | |
| 1603 | - } | |
| 1604 | - | |
| 1605 | - $stats = (object) $stats; | |
| 1606 | - wp_cache_set($cache_key, $stats, 'counts'); | |
| 1607 | - | |
| 1608 | - return $stats; | |
| 1609 | -} | |
| 1610 | - | |
| 1611 | -//20100809ysk start | |
| 1612 | -/** | |
| 1613 | - * custom order meta row | |
| 1614 | - */ | |
| 1615 | -function _list_custom_order_meta_row($key, $entry) { | |
| 1616 | - $r = ''; | |
| 1617 | - $style = ''; | |
| 1618 | - $key = esc_attr($key); | |
| 1619 | - | |
| 1620 | - $name = esc_attr($entry['name']); | |
| 1621 | - $means = get_option('usces_custom_order_select'); | |
| 1622 | - $meansoption = ''; | |
| 1623 | - foreach($means as $meankey => $meanvalue) { | |
| 1624 | - if($meankey == $entry['means']) { | |
| 1625 | - $selected = ' selected="selected"'; | |
| 1626 | - } else { | |
| 1627 | - $selected = ''; | |
| 1628 | - } | |
| 1629 | - $meansoption .= '<option value="'.esc_attr($meankey).'"'.$selected.'>'.esc_html($meanvalue)."</option>\n"; | |
| 1630 | - } | |
| 1631 | - $essential = $entry['essential'] == 1 ? " checked='checked'" : ""; | |
| 1632 | - $value = ''; | |
| 1633 | - if(is_array($entry['value'])) { | |
| 1634 | - foreach($entry['value'] as $k => $v) { | |
| 1635 | - $value .= $v."\n"; | |
| 1636 | - } | |
| 1637 | - } | |
| 1638 | - $value = esc_attr(trim($value)); | |
| 1639 | - | |
| 1640 | - $r .= "\n\t<tr id='csod-{$key}' class='{$style}'>"; | |
| 1641 | - $r .= "\n\t\t<td class='left'><div><input type='text' name='csod[{$key}][key]' id='csod[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; | |
| 1642 | - $r .= "\n\t\t<div><input type='text' name='csod[{$key}][name]' id='csod[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; | |
| 1643 | - $r .= "\n\t\t<div class='optcheck'><select name='csod[{$key}][means]' id='csod[{$key}][means]'>".$meansoption."</select>\n"; | |
| 1644 | - $r .= "<input type='checkbox' name='csod[{$key}][essential]' id='csod[{$key}][essential]' value='1'{$essential} /><label for='csod[{$key}][essential]'>".__('Required','usces')."</label></div>"; | |
| 1645 | -//20100818ysk start | |
| 1646 | - //$r .= "\n\t\t<div class='submit'><input type='button' name='deletecsod[{$key}]' id='deletecsod[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customOrder.del(\"{$key}\");' />"; | |
| 1647 | - //$r .= "\n\t\t<input type='button' name='updatecsod' id='updatecsod[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customOrder.upd(\"{$key}\");' /></div>"; | |
| 1648 | - $r .= "\n\t\t<div class='submit'><input type='button' name='del_csod[{$key}]' id='del_csod[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delOrder(\"{$key}\");' />"; | |
| 1649 | - $r .= "\n\t\t<input type='button' name='upd_csod[{$key}]' id='upd_csod[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updOrder(\"{$key}\");' /></div>"; | |
| 1650 | -//20100818ysk end | |
| 1651 | - $r .= "\n\t\t<div id='csod_loading-{$key}' class='meta_submit_loading'></div>"; | |
| 1652 | - $r .= "</td>"; | |
| 1653 | - $r .= "\n\t\t<td class='item-opt-value'><textarea name='csod[{$key}][value]' id='csod[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; | |
| 1654 | - return $r; | |
| 1655 | -} | |
| 1656 | -//20100809ysk end | |
| 1657 | - | |
| 1658 | -//20100818ysk start | |
| 1659 | -/** | |
| 1660 | - * has custom field meta | |
| 1661 | - */ | |
| 1662 | -function usces_has_custom_field_meta($fieldname) { | |
| 1663 | - switch($fieldname) { | |
| 1664 | - case 'order': | |
| 1665 | - $field = 'usces_custom_order_field'; | |
| 1666 | - break; | |
| 1667 | - case 'customer': | |
| 1668 | - $field = 'usces_custom_customer_field'; | |
| 1669 | - break; | |
| 1670 | - case 'delivery': | |
| 1671 | - $field = 'usces_custom_delivery_field'; | |
| 1672 | - break; | |
| 1673 | - case 'member': | |
| 1674 | - $field = 'usces_custom_member_field'; | |
| 1675 | - break; | |
| 1676 | - default: | |
| 1677 | - return array(); | |
| 1678 | - } | |
| 1679 | - $fields = get_option($field); | |
| 1680 | - if( empty($fields) ){ | |
| 1681 | - $meta = array(); | |
| 1682 | - }elseif( is_array($fields) ){ | |
| 1683 | - $meta = $fields; | |
| 1684 | - }else{ | |
| 1685 | - $meta = unserialize($fields); | |
| 1686 | - } | |
| 1687 | - return $meta; | |
| 1688 | -} | |
| 1689 | - | |
| 1690 | -function usces_getinfo_ajax(){ | |
| 1691 | - global $wp_version; | |
| 1692 | - $wcex_str = ''; | |
| 1693 | - $res = ''; | |
| 1694 | - $wcex = usces_get_wcex(); | |
| 1695 | - foreach ( (array)$wcex as $key => $values ) { | |
| 1696 | - $wcex_str .= $key . "-" . $values['version'] . ","; | |
| 1697 | - } | |
| 1698 | - $wcex_str = rtrim($wcex_str, ','); | |
| 1699 | - if ( version_compare($wp_version, '3.4', '>=') ){ | |
| 1700 | - $theme_ob = wp_get_theme(); | |
| 1701 | - $themedata['Name'] = $theme_ob->get('Name'); | |
| 1702 | - $themedata['Version'] = $theme_ob->get('Version'); | |
| 1703 | - }else{ | |
| 1704 | - $themedata = get_theme_data( get_stylesheet_directory().'/style.css' ); | |
| 1705 | - } | |
| 1706 | - | |
| 1707 | - | |
| 1708 | - $v = urlencode(USCES_VERSION); | |
| 1709 | - $wcid = urlencode(get_option('usces_wcid')); | |
| 1710 | - $locale = urlencode(get_locale()); | |
| 1711 | - $theme = urlencode($themedata['Name'] . '-' . $themedata['Version']); | |
| 1712 | - $wcex = urlencode($wcex_str); | |
| 1713 | - $interface_url = 'http://www.welcart.com/util/welcart_information2.php'; | |
| 1714 | - $wcurl = urlencode(get_home_url()); | |
| 1715 | - $interface = parse_url($interface_url); | |
| 1716 | - | |
| 1717 | - $vars ="v=$v&wcid=$wcid&locale=$locale&theme=$theme&wcex=$wcex&wcurl=$wcurl"; | |
| 1718 | - $header = "POST " . $interface_url . " HTTP/1.1\r\n"; | |
| 1719 | - $header .= "Host: " . $_SERVER['HTTP_HOST'] . "\r\n"; | |
| 1720 | - $header .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n"; | |
| 1721 | - $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; | |
| 1722 | - $header .= "Content-Length: " . strlen($vars) . "\r\n"; | |
| 1723 | - $header .= "Connection: close\r\n\r\n"; | |
| 1724 | - $header .= $vars; | |
| 1725 | - $fp = fsockopen($interface['host'],80,$errno,$errstr,30); | |
| 1726 | - if( $fp ){ | |
| 1727 | - fwrite($fp, $header); | |
| 1728 | - $i=0; | |
| 1729 | - while ( !feof($fp) ) { | |
| 1730 | - $scr = fgets($fp, 10240); | |
| 1731 | - preg_match("/<(title|data)>(.*)<(\/title|\/data)>$/", $scr, $match); | |
| 1732 | - | |
| 1733 | - if(!empty($match[2])){ | |
| 1734 | - switch( $match[1] ){ | |
| 1735 | - case'title': | |
| 1736 | - $res .= '<div style="text-align: center;border-bottom: 1px dotted #CCCCCC;width: 80%;margin-bottom: 10px;padding-bottom: 3px; margin-right: auto; margin-left: auto;"><stlong>' . $match[2] . '</strong></div><ul>'; | |
| 1737 | - break; | |
| 1738 | - case 'data': | |
| 1739 | - $res .= '<li>' . $match[2] . '</li>'; | |
| 1740 | - break; | |
| 1741 | - } | |
| 1742 | - } | |
| 1743 | - $i++; | |
| 1744 | - if($i>50) { | |
| 1745 | - $res = 'ERROR'; | |
| 1746 | - break; | |
| 1747 | - } | |
| 1748 | - } | |
| 1749 | - | |
| 1750 | - $res .= '</ul>'; | |
| 1751 | - fclose($fp); | |
| 1752 | - | |
| 1753 | - }else{ | |
| 1754 | - $res = 'ERROR'; | |
| 1755 | - } | |
| 1756 | - die($res); | |
| 1757 | -} | |
| 1758 | - | |
| 1759 | -/** | |
| 1760 | - * custom field ajax | |
| 1761 | - */ | |
| 1762 | -function custom_field_ajax() { | |
| 1763 | - global $usces; | |
| 1764 | - | |
| 1765 | - check_admin_referer( 'custom_field_ajax', 'wc_nonce' ); | |
| 1766 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 1767 | - | |
| 1768 | - if($_POST['action'] != 'custom_field_ajax') die(0); | |
| 1769 | - switch($_POST['field']) { | |
| 1770 | - case 'order': | |
| 1771 | - $field = 'usces_custom_order_field'; | |
| 1772 | - break; | |
| 1773 | - case 'customer': | |
| 1774 | - $field = 'usces_custom_customer_field'; | |
| 1775 | - break; | |
| 1776 | - case 'delivery': | |
| 1777 | - $field = 'usces_custom_delivery_field'; | |
| 1778 | - break; | |
| 1779 | - case 'member': | |
| 1780 | - $field = 'usces_custom_member_field'; | |
| 1781 | - break; | |
| 1782 | - default: | |
| 1783 | - die(0); | |
| 1784 | - } | |
| 1785 | - | |
| 1786 | - $meta = usces_has_custom_field_meta($_POST['field']); | |
| 1787 | - $dupkey = 0; | |
| 1788 | - | |
| 1789 | - if(isset($_POST['add'])) { | |
| 1790 | - $newkey = isset($_POST['newkey']) ? trim($_POST['newkey']) : ''; | |
| 1791 | - $newname = isset($_POST['newname']) ? trim($_POST['newname']) : ''; | |
| 1792 | - $newmeans = isset($_POST['newmeans']) ? $_POST['newmeans'] : 0; | |
| 1793 | - $newessential = isset($_POST['newessential']) ? $_POST['newessential'] : 0; | |
| 1794 | - $newposition = isset($_POST['newposition']) ? trim($_POST['newposition']) : ''; | |
| 1795 | - | |
| 1796 | - if($newmeans == 2) {//Text | |
| 1797 | - $newvalue = ''; | |
| 1798 | - $nv = $newvalue; | |
| 1799 | - $required_entry = ( !empty( $newkey ) && !empty( $newname ) ) ? true : false; | |
| 1800 | - } else { | |
| 1801 | - $newvalue = isset($_POST['newvalue']) ? explode('\n', trim($_POST['newvalue'])) : ''; | |
| 1802 | - foreach((array)$newvalue as $v) { | |
| 1803 | - if( !WCUtils::is_blank($v) ) | |
| 1804 | - $nv[] = trim($v); | |
| 1805 | - } | |
| 1806 | - $required_entry = ( ( !empty( $newvalue ) ) && !empty( $newkey ) && !empty( $newname ) ) ? true : false; | |
| 1807 | - } | |
| 1808 | - | |
| 1809 | - | |
| 1810 | - if(!array_key_exists($newkey, $meta)) { | |
| 1811 | - if( $required_entry ) { | |
| 1812 | - $meta[$newkey]['name'] = $newname; | |
| 1813 | - $meta[$newkey]['means'] = $newmeans; | |
| 1814 | - $meta[$newkey]['essential'] = $newessential; | |
| 1815 | - $meta[$newkey]['value'] = $nv; | |
| 1816 | - if( !WCUtils::is_blank($newposition) ) $meta[$newkey]['position'] = $newposition; | |
| 1817 | - update_option($field, $meta); | |
| 1818 | - } | |
| 1819 | - } else { | |
| 1820 | - $dupkey = 1; | |
| 1821 | - } | |
| 1822 | - | |
| 1823 | - } elseif(isset($_POST['update'])) { | |
| 1824 | - $key = isset($_POST['key']) ? trim($_POST['key']) : ''; | |
| 1825 | - $name = isset($_POST['name']) ? trim($_POST['name']) : ''; | |
| 1826 | - $means = isset($_POST['means']) ? $_POST['means'] : 0; | |
| 1827 | - $essential = isset($_POST['essential']) ? $_POST['essential'] : 0; | |
| 1828 | - $position = isset($_POST['position']) ? trim($_POST['position']) : ''; | |
| 1829 | - | |
| 1830 | - if($means == 2) {//Text | |
| 1831 | - $value = ''; | |
| 1832 | - $nv = $value; | |
| 1833 | - $required_entry = ( !empty( $key ) && !empty( $name ) ) ? true : false; | |
| 1834 | - | |
| 1835 | - } else { | |
| 1836 | - $value = isset($_POST['value']) ? explode('\n', trim($_POST['value'])) : ''; | |
| 1837 | - foreach((array)$value as $v) { | |
| 1838 | - if( !WCUtils::is_blank($v) ) | |
| 1839 | - $nv[] = trim($v); | |
| 1840 | - } | |
| 1841 | - $required_entry = ( ( !empty( $value ) ) && !empty( $key ) && !empty( $name ) ) ? true : false; | |
| 1842 | - } | |
| 1843 | - | |
| 1844 | - if( $required_entry ) { | |
| 1845 | - $meta[$key]['name'] = $name; | |
| 1846 | - $meta[$key]['means'] = $means; | |
| 1847 | - $meta[$key]['essential'] = $essential; | |
| 1848 | - $meta[$key]['value'] = $nv; | |
| 1849 | - if( !WCUtils::is_blank($position) ) $meta[$key]['position'] = $position; | |
| 1850 | - update_option($field, $meta); | |
| 1851 | - } | |
| 1852 | - | |
| 1853 | - } elseif(isset($_POST['delete'])) { | |
| 1854 | - $key = isset($_POST['key']) ? trim($_POST['key']) : ''; | |
| 1855 | - unset($meta[$key]); | |
| 1856 | - update_option($field, $meta); | |
| 1857 | - } | |
| 1858 | - | |
| 1859 | - $r = ''; | |
| 1860 | - switch($_POST['field']) { | |
| 1861 | - case 'order': | |
| 1862 | - foreach($meta as $key => $entry) | |
| 1863 | - $r .= _list_custom_order_meta_row($key, $entry); | |
| 1864 | - break; | |
| 1865 | - case 'customer': | |
| 1866 | - foreach($meta as $key => $entry) | |
| 1867 | - $r .= _list_custom_customer_meta_row($key, $entry); | |
| 1868 | - break; | |
| 1869 | - case 'delivery': | |
| 1870 | - foreach($meta as $key => $entry) | |
| 1871 | - $r .= _list_custom_delivery_meta_row($key, $entry); | |
| 1872 | - break; | |
| 1873 | - case 'member': | |
| 1874 | - foreach($meta as $key => $entry) | |
| 1875 | - $r .= _list_custom_member_meta_row($key, $entry); | |
| 1876 | - break; | |
| 1877 | - } | |
| 1878 | - | |
| 1879 | - $res = $r . '#usces#' . $dupkey; | |
| 1880 | - //REGEX BUG: but it'll return info | |
| 1881 | - // Compose JavaScript for return | |
| 1882 | - die($res); | |
| 1883 | -} | |
| 1884 | - | |
| 1885 | -/** | |
| 1886 | - * list custom customer meta row | |
| 1887 | - */ | |
| 1888 | -function _list_custom_customer_meta_row($key, $entry) { | |
| 1889 | - $r = ''; | |
| 1890 | - $style = ''; | |
| 1891 | - $key = esc_attr($key); | |
| 1892 | - | |
| 1893 | - $name = esc_attr($entry['name']); | |
| 1894 | - $means = get_option('usces_custom_customer_select'); | |
| 1895 | - $meansoption = ''; | |
| 1896 | - foreach($means as $meankey => $meanvalue) { | |
| 1897 | - $selected = ($meankey == $entry['means']) ? " selected='selected'" : ""; | |
| 1898 | - $meansoption .= "<option value='".esc_attr($meankey)."'".$selected.">".esc_html($meanvalue)."</option>\n"; | |
| 1899 | - } | |
| 1900 | - $essential = $entry['essential'] == 1 ? " checked='checked'" : ""; | |
| 1901 | - $value = ''; | |
| 1902 | - if(is_array($entry['value'])) { | |
| 1903 | - foreach($entry['value'] as $k => $v) { | |
| 1904 | - $value .= $v."\n"; | |
| 1905 | - } | |
| 1906 | - } | |
| 1907 | - $value = esc_attr(trim($value)); | |
| 1908 | - $positions = get_option('usces_custom_field_position_select'); | |
| 1909 | - $positionsoption = ''; | |
| 1910 | - foreach($positions as $poskey => $posvalue) { | |
| 1911 | - $selected = ($poskey == $entry['position']) ? " selected='selected'" : ""; | |
| 1912 | - $positionsoption .= "<option value='".esc_attr($poskey)."'".$selected.">".esc_html($posvalue)."</option>\n"; | |
| 1913 | - } | |
| 1914 | - | |
| 1915 | - $r .= "\n\t<tr id='cscs-{$key}' class='{$style}'>"; | |
| 1916 | - $r .= "\n\t\t<td class='left'><div><input type='text' name='cscs[{$key}][key]' id='cscs[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; | |
| 1917 | - $r .= "\n\t\t<div><input type='text' name='cscs[{$key}][name]' id='cscs[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; | |
| 1918 | - $r .= "\n\t\t<div class='optcheck'><select name='cscs[{$key}][means]' id='cscs[{$key}][means]'>".$meansoption."</select>\n"; | |
| 1919 | - $r .= "<input type='checkbox' name='cscs[{$key}][essential]' id='cscs[{$key}][essential]' value='1'{$essential} /><label for='cscs[{$key}][essential]'>".__('Required','usces')."</label>\n"; | |
| 1920 | - $r .= "<select name='cscs[{$key}][position]' id='cscs[{$key}][position]'>".$positionsoption."</select></div>"; | |
| 1921 | - $r .= "\n\t\t<div class='submit'><input type='button' name='del_cscs[{$key}]' id='del_cscs[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delCustomer(\"{$key}\");' />"; | |
| 1922 | - $r .= "\n\t\t<input type='button' name='upd_cscs[{$key}]' id='upd_cscs[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updCustomer(\"{$key}\");' /></div>"; | |
| 1923 | - $r .= "\n\t\t<div id='cscs_loading-{$key}' class='meta_submit_loading'></div>"; | |
| 1924 | - $r .= "</td>"; | |
| 1925 | - $r .= "\n\t\t<td class='item-opt-value'><textarea name='cscs[{$key}][value]' id='cscs[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; | |
| 1926 | - return $r; | |
| 1927 | -} | |
| 1928 | - | |
| 1929 | -/** | |
| 1930 | - * list custom delivery meta row | |
| 1931 | - */ | |
| 1932 | -function _list_custom_delivery_meta_row($key, $entry) { | |
| 1933 | - $r = ''; | |
| 1934 | - $style = ''; | |
| 1935 | - $key = esc_attr($key); | |
| 1936 | - | |
| 1937 | - $name = esc_attr($entry['name']); | |
| 1938 | - $means = get_option('usces_custom_delivery_select'); | |
| 1939 | - $meansoption = ''; | |
| 1940 | - foreach($means as $meankey => $meanvalue) { | |
| 1941 | - $selected = ($meankey == $entry['means']) ? " selected='selected'" : ""; | |
| 1942 | - $meansoption .= "<option value='".esc_attr($meankey)."'".$selected.">".esc_html($meanvalue)."</option>\n"; | |
| 1943 | - } | |
| 1944 | - $essential = $entry['essential'] == 1 ? " checked='checked'" : ""; | |
| 1945 | - $value = ''; | |
| 1946 | - if(is_array($entry['value'])) { | |
| 1947 | - foreach($entry['value'] as $k => $v) { | |
| 1948 | - $value .= $v."\n"; | |
| 1949 | - } | |
| 1950 | - } | |
| 1951 | - $value = esc_attr(trim($value)); | |
| 1952 | - $positions = get_option('usces_custom_field_position_select'); | |
| 1953 | - $positionsoption = ''; | |
| 1954 | - foreach($positions as $poskey => $posvalue) { | |
| 1955 | - $selected = ($poskey == $entry['position']) ? " selected='selected'" : ""; | |
| 1956 | - $positionsoption .= "<option value='".esc_attr($poskey)."'".$selected.">".esc_html($posvalue)."</option>\n"; | |
| 1957 | - } | |
| 1958 | - | |
| 1959 | - $r .= "\n\t<tr id='csde-{$key}' class='{$style}'>"; | |
| 1960 | - $r .= "\n\t\t<td class='left'><div><input type='text' name='csde[{$key}][key]' id='csde[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; | |
| 1961 | - $r .= "\n\t\t<div><input type='text' name='csde[{$key}][name]' id='csde[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; | |
| 1962 | - $r .= "\n\t\t<div class='optcheck'><select name='csde[{$key}][means]' id='csde[{$key}][means]'>".$meansoption."</select>\n"; | |
| 1963 | - $r .= "<input type='checkbox' name='csde[{$key}][essential]' id='csde[{$key}][essential]' value='1'{$essential} /><label for='csde[{$key}][essential]'>".__('Required','usces')."</label>\n"; | |
| 1964 | - $r .= "<select name='csde[{$key}][position]' id='csde[{$key}][position]'>".$positionsoption."</select></div>"; | |
| 1965 | - $r .= "\n\t\t<div class='submit'><input type='button' name='del_csde[{$key}]' id='del_csde[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delDelivery(\"{$key}\");' />"; | |
| 1966 | - $r .= "\n\t\t<input type='button' name='upd_csde[{$key}]' id='upd_csde[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updDelivery(\"{$key}\");' /></div>"; | |
| 1967 | - $r .= "\n\t\t<div id='csde_loading-{$key}' class='meta_submit_loading'></div>"; | |
| 1968 | - $r .= "</td>"; | |
| 1969 | - $r .= "\n\t\t<td class='item-opt-value'><textarea name='csde[{$key}][value]' id='csde[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; | |
| 1970 | - return $r; | |
| 1971 | -} | |
| 1972 | - | |
| 1973 | -/** | |
| 1974 | - * list custom member meta row | |
| 1975 | - */ | |
| 1976 | -function _list_custom_member_meta_row($key, $entry) { | |
| 1977 | - $r = ''; | |
| 1978 | - $style = ''; | |
| 1979 | - $key = esc_attr($key); | |
| 1980 | - | |
| 1981 | - $name = esc_attr($entry['name']); | |
| 1982 | - $means = get_option('usces_custom_member_select'); | |
| 1983 | - $meansoption = ''; | |
| 1984 | - foreach($means as $meankey => $meanvalue) { | |
| 1985 | - $selected = ($meankey == $entry['means']) ? " selected='selected'" : ""; | |
| 1986 | - $meansoption .= "<option value='".esc_attr($meankey)."'".$selected.">".esc_html($meanvalue)."</option>\n"; | |
| 1987 | - } | |
| 1988 | - $essential = $entry['essential'] == 1 ? " checked='checked'" : ""; | |
| 1989 | - $value = ''; | |
| 1990 | - if(is_array($entry['value'])) { | |
| 1991 | - foreach($entry['value'] as $k => $v) { | |
| 1992 | - $value .= $v."\n"; | |
| 1993 | - } | |
| 1994 | - } | |
| 1995 | - $value = esc_attr(trim($value)); | |
| 1996 | - $positions = get_option('usces_custom_field_position_select'); | |
| 1997 | - $positionsoption = ''; | |
| 1998 | - foreach($positions as $poskey => $posvalue) { | |
| 1999 | - $selected = ($poskey == $entry['position']) ? " selected='selected'" : ""; | |
| 2000 | - $positionsoption .= "<option value='".esc_attr($poskey)."'".$selected.">".esc_attr($posvalue)."</option>\n"; | |
| 2001 | - } | |
| 2002 | - $r .= "\n\t<tr id='csmb-{$key}' class='{$style}'>"; | |
| 2003 | - $r .= "\n\t\t<td class='left'><div><input type='text' name='csmb[{$key}][key]' id='csmb[{$key}][key]' class='optname' size='20' value='{$key}' readonly /></div>"; | |
| 2004 | - $r .= "\n\t\t<div><input type='text' name='csmb[{$key}][name]' id='csmb[{$key}][name]' class='optname' size='20' value='{$name}' /></div>"; | |
| 2005 | - $r .= "\n\t\t<div class='optcheck'><select name='csmb[{$key}][means]' id='csmb[{$key}][means]'>".$meansoption."</select>\n"; | |
| 2006 | - $r .= "<input type='checkbox' name='csmb[{$key}][essential]' id='csmb[{$key}][essential]' value='1'{$essential} /><label for='csmb[{$key}][essential]'>".__('Required','usces')."</label>\n"; | |
| 2007 | - $r .= "<select name='csmb[{$key}][position]' id='csmb[{$key}][position]'>".$positionsoption."</select></div>"; | |
| 2008 | - $r .= "\n\t\t<div class='submit'><input type='button' name='del_csmb[{$key}]' id='del_csmb[{$key}]' value='".esc_attr(__( 'Delete' ))."' onclick='customField.delMember(\"{$key}\");' />"; | |
| 2009 | - $r .= "\n\t\t<input type='button' name='upd_csmb[{$key}]' id='upd_csmb[{$key}]' value='".esc_attr(__( 'Update' ))."' onclick='customField.updMember(\"{$key}\");' /></div>"; | |
| 2010 | - $r .= "\n\t\t<div id='csmb_loading-{$key}' class='meta_submit_loading'></div>"; | |
| 2011 | - $r .= "</td>"; | |
| 2012 | - $r .= "\n\t\t<td class='item-opt-value'><textarea name='csmb[{$key}][value]' id='csmb[{$key}][value]' class='optvalue'>{$value}</textarea></td>\n\t</tr>"; | |
| 2013 | - return $r; | |
| 2014 | -} | |
| 2015 | -//20100818ysk end | |
| 2016 | - | |
| 2017 | -function change_states_ajax(){ | |
| 2018 | - global $usces, $usces_states; | |
| 2019 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 2020 | - | |
| 2021 | - $c = $_POST['country']; | |
| 2022 | - $res = ''; | |
| 2023 | -//20110331ysk start | |
| 2024 | -/* if( !isset($usces_states[$c]) || empty($usces_states[$c]) ) | |
| 2025 | - die('error'); | |
| 2026 | - | |
| 2027 | - foreach( (array)$usces_states[$c] as $state ){ | |
| 2028 | - $res .= '<option value="' . $state . '">' . $state . '</option>'; | |
| 2029 | - }*/ | |
| 2030 | - $prefs = get_usces_states($c); | |
| 2031 | - if(is_array($prefs) and 0 < count($prefs)) { | |
| 2032 | - foreach((array)$prefs as $state) { | |
| 2033 | - $res .= '<option value="' . $state . '">' . $state . '</option>'; | |
| 2034 | - } | |
| 2035 | - } else { | |
| 2036 | - die('error'); | |
| 2037 | - } | |
| 2038 | -//20110331ysk end | |
| 2039 | - die($res); | |
| 2040 | -} | |
| 2041 | - | |
| 2042 | -//20110331ysk start | |
| 2043 | -function get_usces_states($country) { | |
| 2044 | - global $usces, $usces_states; | |
| 2045 | - | |
| 2046 | - $states = array(); | |
| 2047 | - $prefs = maybe_unserialize($usces->options['province']); | |
| 2048 | - if( !isset($prefs[$country]) || empty($prefs[$country]) ) { | |
| 2049 | - if($country == $usces->options['system']['base_country']) { | |
| 2050 | - foreach((array)$prefs as $state) { | |
| 2051 | - if(!is_array($state)) | |
| 2052 | - array_push($states, $state); | |
| 2053 | - } | |
| 2054 | - if(count($states) == 0) { | |
| 2055 | - if( !empty($usces_states[$country]) ) { | |
| 2056 | - $prefs = $usces_states[$country]; | |
| 2057 | - if(is_array($prefs)) { | |
| 2058 | - $states = $prefs; | |
| 2059 | - } | |
| 2060 | - } | |
| 2061 | - } | |
| 2062 | - } else { | |
| 2063 | - if( !empty($usces_states[$country]) ) { | |
| 2064 | - $prefs = $usces_states[$country]; | |
| 2065 | - if(is_array($prefs)) { | |
| 2066 | - $states = $prefs; | |
| 2067 | - } | |
| 2068 | - } | |
| 2069 | - } | |
| 2070 | - } else { | |
| 2071 | - $states = $prefs[$country]; | |
| 2072 | - } | |
| 2073 | - return $states; | |
| 2074 | -} | |
| 2075 | - | |
| 2076 | -function target_market_ajax() { | |
| 2077 | - global $usces; | |
| 2078 | - | |
| 2079 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 2080 | - $res = ""; | |
| 2081 | - $target = explode(",", $_POST['target']); | |
| 2082 | - foreach((array)$target as $country) { | |
| 2083 | - $prefs = get_usces_states($country); | |
| 2084 | - if(is_array($prefs) and 0 < count($prefs)) { | |
| 2085 | - $pos = strpos($prefs[0], '--'); | |
| 2086 | - if($pos !== false) array_shift($prefs); | |
| 2087 | - $res .= $country.","; | |
| 2088 | - foreach((array)$prefs as $state) { | |
| 2089 | - $res .= $state."\n"; | |
| 2090 | - } | |
| 2091 | - $res = rtrim($res, "\n")."#usces#"; | |
| 2092 | -//20110430ysk start | |
| 2093 | - } else { | |
| 2094 | - $res .= $country.",#usces#"; | |
| 2095 | -//20110430ysk end | |
| 2096 | - } | |
| 2097 | - } | |
| 2098 | - $res = rtrim($res, "#usces#"); | |
| 2099 | - die($res); | |
| 2100 | -} | |
| 2101 | -//20110331ysk end | |
| 2102 | -//20120309ysk start 0000430 | |
| 2103 | -function usces_admin_ajax() { | |
| 2104 | - switch($_POST['mode']) { | |
| 2105 | - case 'options_backup': | |
| 2106 | - check_admin_referer( 'options_backup', 'wc_nonce' ); | |
| 2107 | - $options = get_option('usces'); | |
| 2108 | - $res = true; | |
| 2109 | - if( is_array($options) ) { | |
| 2110 | - $usces_backup_date = current_time('mysql'); | |
| 2111 | - update_option('usces_backup', $options); | |
| 2112 | - update_option('usces_backup_date', $usces_backup_date); | |
| 2113 | - $res = $usces_backup_date; | |
| 2114 | - } else { | |
| 2115 | - $res = false; | |
| 2116 | - } | |
| 2117 | - die($res); | |
| 2118 | - break; | |
| 2119 | - case 'options_restore': | |
| 2120 | - check_admin_referer( 'options_restore', 'wc_nonce' ); | |
| 2121 | - $options = get_option('usces_backup'); | |
| 2122 | - $res = true; | |
| 2123 | - if( is_array($options) ) { | |
| 2124 | - update_option('usces', $options); | |
| 2125 | - } else { | |
| 2126 | - $res = false; | |
| 2127 | - } | |
| 2128 | - die($res); | |
| 2129 | - break; | |
| 2130 | - } | |
| 2131 | - do_action('usces_action_admin_ajax'); | |
| 2132 | -} | |
| 2133 | -//20120309ysk end | |
| 2134 | -function usces_order_recalculation( $order_id, $mem_id, $post_ids, $skus, $prices, $quants, $use_point, $shipping_charge, $cod_fee ) { | |
| 2135 | - global $usces; | |
| 2136 | - | |
| 2137 | - $res = 'ok'; | |
| 2138 | - if( !empty($order_id) ) { | |
| 2139 | - $data = $usces->get_order_data( $order_id, 'direct' ); | |
| 2140 | - $condition = unserialize( $data['order_condition'] ); | |
| 2141 | - } else { | |
| 2142 | - $condition = $usces->get_condition(); | |
| 2143 | - } | |
| 2144 | -//usces_log('condition : '.print_r($condition,true), 'acting_transaction.log'); | |
| 2145 | - | |
| 2146 | - $post_id = explode("#usces#", $post_ids); | |
| 2147 | - //$sku = explode("#usces#", $skus); | |
| 2148 | - $price = explode("#usces#", $prices); | |
| 2149 | - $quant = explode("#usces#", $quants); | |
| 2150 | - $cart = array(); | |
| 2151 | - for( $i = 0; $i < count($post_id); $i++ ) { | |
| 2152 | - if( $post_id[$i] ) | |
| 2153 | - //$cart[] = array( "post_id"=>$post_id[$i], "sku"=>$sku[$i], "price"=>$price[$i], "quantity"=>$quant[$i] ); | |
| 2154 | - $cart[] = array( "post_id"=>$post_id[$i], "price"=>$price[$i], "quantity"=>$quant[$i] ); | |
| 2155 | - } | |
| 2156 | - | |
| 2157 | - $total_items_price = 0; | |
| 2158 | - foreach( $cart as $cart_row ) { | |
| 2159 | - $total_items_price += $cart_row['price'] * $cart_row['quantity']; | |
| 2160 | - } | |
| 2161 | - $meminfo = $usces->get_member_info( $mem_id ); | |
| 2162 | - | |
| 2163 | - $discount = 0; | |
| 2164 | - if( $condition['display_mode'] == 'Promotionsale' ) { | |
| 2165 | - if( $condition['campaign_privilege'] == 'discount' ) { | |
| 2166 | - if ( 0 === (int)$condition['campaign_category'] ) { | |
| 2167 | - $discount = $total_items_price * $condition['privilege_discount'] / 100; | |
| 2168 | - } else { | |
| 2169 | - foreach( $cart as $cart_row ) { | |
| 2170 | - if( in_category( (int)$condition['campaign_category'], $cart_row['post_id']) ) { | |
| 2171 | - $discount += $cart_row['price'] * $cart_row['quantity'] * $condition['privilege_discount'] / 100; | |
| 2172 | - } | |
| 2173 | - } | |
| 2174 | - } | |
| 2175 | - } | |
| 2176 | - } | |
| 2177 | - if( 0 < $discount ) $discount = ceil($discount * -1); | |
| 2178 | - | |
| 2179 | - $point = 0; | |
| 2180 | - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($meminfo['ID']) ) { | |
| 2181 | - if( $condition['display_mode'] == 'Promotionsale' ) { | |
| 2182 | - if( $condition['campaign_privilege'] == 'discount' ) { | |
| 2183 | - foreach( $cart as $cart_row ) { | |
| 2184 | - $cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); | |
| 2185 | - if( !in_array( $condition['campaign_category'], $cats ) ) { | |
| 2186 | - $rate = get_post_meta( $cart_row['post_id'], '_itemPointrate', true ); | |
| 2187 | - $price = $cart_row['price'] * $cart_row['quantity']; | |
| 2188 | - $point += $price * $rate / 100; | |
| 2189 | - } | |
| 2190 | - } | |
| 2191 | - } elseif( $condition['campaign_privilege'] == 'point' ) { | |
| 2192 | - foreach( $cart as $cart_row ) { | |
| 2193 | - $rate = get_post_meta( $cart_row['post_id'], '_itemPointrate', true ); | |
| 2194 | - $price = $cart_row['price'] * $cart_row['quantity']; | |
| 2195 | - $cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); | |
| 2196 | - if( in_array( $condition['campaign_category'], $cats ) ) { | |
| 2197 | - $point += $price * $rate / 100 * $condition['privilege_point']; | |
| 2198 | - } else { | |
| 2199 | - $point += $price * $rate / 100; | |
| 2200 | - } | |
| 2201 | - } | |
| 2202 | - } | |
| 2203 | - } else { | |
| 2204 | - foreach( $cart as $cart_row ) { | |
| 2205 | - $rate = get_post_meta( $cart_row['post_id'], '_itemPointrate', true ); | |
| 2206 | - $price = $cart_row['price'] * $cart_row['quantity']; | |
| 2207 | - $point += $price * $rate / 100; | |
| 2208 | - } | |
| 2209 | - } | |
| 2210 | - } | |
| 2211 | - | |
| 2212 | - if( 0 < $point ) $point = ceil($point); | |
| 2213 | -//20130425ysk start 0000699 | |
| 2214 | - if( 0 < $use_point ) { | |
| 2215 | - $point = ceil( $point - ( $point * $use_point / $total_items_price ) ); | |
| 2216 | - if( 0 > $point ) | |
| 2217 | - $point = 0; | |
| 2218 | - } | |
| 2219 | -//20130425ysk end | |
| 2220 | - $discount = apply_filters('usces_filter_order_discount_recalculation', $discount, $cart); | |
| 2221 | - $point = apply_filters( 'usces_filter_set_point_recalculation', $point, $condition, $cart, $meminfo, $use_point ); | |
| 2222 | - $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee; | |
| 2223 | - $total_price = apply_filters('usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee); | |
| 2224 | - $materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'discount' ); | |
| 2225 | - $tax = $usces->getTax( $total_price, $materials ); | |
| 2226 | - $total_full_price = $total_price + $tax; | |
| 2227 | - $total_full_price = apply_filters('usces_filter_set_cart_fees_total_full_price', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee); | |
| 2228 | - | |
| 2229 | - return $res."#usces#".$discount."#usces#".usces_crform( $tax, false, false, 'return', false )."#usces#".$point."#usces#".usces_crform( $total_full_price, false, false, 'return', false ); | |
| 2230 | -} | |
| 2231 | -?> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Welcart SKU and Options | |
| 4 | + * | |
| 5 | + * Functions for manipulating SKUs and Options in product registration. | |
| 6 | + * | |
| 7 | + * @package Welcart | |
| 8 | + */ | |
| 9 | + | |
| 10 | +defined( 'ABSPATH' ) || exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Add Item SKU. | |
| 14 | + * | |
| 15 | + * @since 2.3.3 | |
| 16 | + * @param string $post_id Post ID. | |
| 17 | + * @param string $new_sku SKU data. | |
| 18 | + * @param boolean $check Switch of check. | |
| 19 | + * @return New meta id. | |
| 20 | + */ | |
| 21 | +function usces_add_sku( $post_id, $new_sku, $check = true ) { | |
| 22 | + global $wpdb, $usces; | |
| 23 | + | |
| 24 | + if ( $check ) { | |
| 25 | + | |
| 26 | + $skus = wel_get_skus( $post_id, 'sort', false ); | |
| 27 | + | |
| 28 | + if ( ! empty( $skus ) ) { | |
| 29 | + | |
| 30 | + $sku_num = count( $skus ); | |
| 31 | + $unique = true; | |
| 32 | + $sortnull = true; | |
| 33 | + $sort = array(); | |
| 34 | + foreach ( (array) $skus as $sku ) { | |
| 35 | + | |
| 36 | + if ( (string) $sku['code'] === (string) $new_sku['code'] ) { | |
| 37 | + $unique = false; | |
| 38 | + } | |
| 39 | + if ( ! isset( $sku['sort'] ) ) { | |
| 40 | + $sortnull = false; | |
| 41 | + } | |
| 42 | + $sort[] = $sku['sort']; | |
| 43 | + } | |
| 44 | + if ( ! $unique ) { | |
| 45 | + return -1; | |
| 46 | + } | |
| 47 | + | |
| 48 | + rsort( $sort ); | |
| 49 | + $next_number = $sort[0] + 1; | |
| 50 | + $unique_sort = array_unique( $sort ); | |
| 51 | + if ( count( $unique_sort ) !== $sku_num || $sku_num != $next_number || ! $sortnull ) { | |
| 52 | + // To repair the sort data. | |
| 53 | + $i = 0; | |
| 54 | + foreach ( (array) $skus as $sku ) { | |
| 55 | + $sku['sort'] = $i; | |
| 56 | + wel_update_sku_data_by_id( $sku['meta_id'], $post_id, $sku ); | |
| 57 | + $i++; | |
| 58 | + } | |
| 59 | + } | |
| 60 | + } | |
| 61 | + $new_sku['sort'] = ! empty( $sku_num ) ? $sku_num : 0; | |
| 62 | + } | |
| 63 | + $new_sku = $usces->stripslashes_deep_post( $new_sku ); | |
| 64 | + $new_meta_id = wel_add_sku_data( $post_id, $new_sku ); | |
| 65 | + | |
| 66 | + return $new_meta_id; | |
| 67 | +} | |
| 68 | + | |
| 69 | +/** | |
| 70 | + * Add Item SKU by ajax. | |
| 71 | + * Ajax response when a new SKU is registered in the SKU block on the product registration screen. | |
| 72 | + * | |
| 73 | + * @since 2.3.3 | |
| 74 | + * @param string $post_ID Post ID. | |
| 75 | + * @return New meta id. | |
| 76 | + */ | |
| 77 | +function add_item_sku_meta( $post_ID ) { | |
| 78 | + global $usces; | |
| 79 | + | |
| 80 | + $post_id = (int) $post_ID; | |
| 81 | + $value = array(); | |
| 82 | + $skus = array(); | |
| 83 | + $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); | |
| 84 | + | |
| 85 | + $args = array( | |
| 86 | + 'newskuname' => FILTER_DEFAULT, | |
| 87 | + 'newskucprice' => FILTER_DEFAULT, | |
| 88 | + 'newskuprice' => FILTER_DEFAULT, | |
| 89 | + 'newskuzaikonum' => FILTER_DEFAULT, | |
| 90 | + 'newskuzaikoselect' => FILTER_DEFAULT, | |
| 91 | + 'newskudisp' => FILTER_DEFAULT, | |
| 92 | + 'newskuunit' => FILTER_DEFAULT, | |
| 93 | + 'newskugptekiyo' => FILTER_DEFAULT, | |
| 94 | + 'newskutaxrate' => FILTER_DEFAULT, | |
| 95 | + ); | |
| 96 | + | |
| 97 | + $inputs = filter_input_array( INPUT_POST, $args ); | |
| 98 | + | |
| 99 | + $newskuname = ( null !== $inputs['newskuname'] ) ? trim( $inputs['newskuname'] ) : ''; | |
| 100 | + $newskucprice = ( null !== $inputs['newskucprice'] ) ? $inputs['newskucprice'] : ''; | |
| 101 | + $newskuprice = ( null !== $inputs['newskuprice'] ) ? $inputs['newskuprice'] : ''; | |
| 102 | + $newskuzaikonum = ( null !== $inputs['newskuzaikonum'] ) ? $inputs['newskuzaikonum'] : ''; | |
| 103 | + $newskuzaikoselect = ( null !== $inputs['newskuzaikoselect'] ) ? $inputs['newskuzaikoselect'] : ''; | |
| 104 | + $newskudisp = ( null !== $inputs['newskudisp'] ) ? trim( $inputs['newskudisp'] ) : ''; | |
| 105 | + $newskuunit = ( null !== $inputs['newskuunit'] ) ? trim( $inputs['newskuunit'] ) : ''; | |
| 106 | + $newskugptekiyo = ( null !== $inputs['newskugptekiyo'] ) ? $inputs['newskugptekiyo'] : ''; | |
| 107 | + $newskutaxrate = ( null !== $inputs['newskutaxrate'] ) ? $inputs['newskutaxrate'] : ''; | |
| 108 | + | |
| 109 | + if ( ! WCUtils::is_blank( $newskuname ) && ! WCUtils::is_blank( $newskuprice ) && ! WCUtils::is_blank( $newskuzaikoselect ) ) { | |
| 110 | + | |
| 111 | + if ( in_array( $newskuname, $protected ) ) { | |
| 112 | + return false; | |
| 113 | + } | |
| 114 | + | |
| 115 | + $value['code'] = $newskuname; | |
| 116 | + $value['name'] = $newskudisp; | |
| 117 | + $value['cprice'] = $newskucprice; | |
| 118 | + $value['price'] = $newskuprice; | |
| 119 | + $value['unit'] = $newskuunit; | |
| 120 | + $value['stocknum'] = $newskuzaikonum; | |
| 121 | + $value['stock'] = $newskuzaikoselect; | |
| 122 | + $value['gp'] = $newskugptekiyo; | |
| 123 | + $value['taxrate'] = $newskutaxrate; | |
| 124 | + | |
| 125 | + $value = apply_filters( 'usces_filter_add_item_sku_meta_value', $value ); | |
| 126 | + | |
| 127 | + $res = apply_filters( 'usces_filter_before_add_item_sku_meta', false, $post_id, $value ); | |
| 128 | + if ( false !== $res ) { | |
| 129 | + return $res; | |
| 130 | + } | |
| 131 | + | |
| 132 | + $id = usces_add_sku( $post_ID, $value, true ); | |
| 133 | + | |
| 134 | + return $id; | |
| 135 | + } else { | |
| 136 | + return false; | |
| 137 | + } | |
| 138 | +} | |
| 139 | + | |
| 140 | +/** | |
| 141 | + * Update Item SKU by ajax. | |
| 142 | + * Ajax response when SKU information is updated in the SKU block of the product registration screen. | |
| 143 | + * | |
| 144 | + * @since 2.3.3 | |
| 145 | + * @param string $post_ID Post ID. | |
| 146 | + * @return Query result. | |
| 147 | + */ | |
| 148 | +function up_item_sku_meta( $post_ID ) { | |
| 149 | + global $wpdb, $usces; | |
| 150 | + | |
| 151 | + $post_id = (int) $post_ID; | |
| 152 | + $value = array(); | |
| 153 | + | |
| 154 | + $skucode = filter_input( INPUT_POST, 'skuname', FILTER_DEFAULT ); | |
| 155 | + $skumetaid = filter_input( INPUT_POST, 'skumetaid', FILTER_DEFAULT ); | |
| 156 | + | |
| 157 | + $res = apply_filters( 'usces_filter_before_up_item_sku_meta', false, $post_ID, $skumetaid, $skucode ); | |
| 158 | + if ( false !== $res ) { | |
| 159 | + return $res; | |
| 160 | + } | |
| 161 | + | |
| 162 | + $args = array( | |
| 163 | + 'skucprice' => FILTER_DEFAULT, | |
| 164 | + 'skuprice' => FILTER_DEFAULT, | |
| 165 | + 'skuzaikonum' => FILTER_DEFAULT, | |
| 166 | + 'skuzaiko' => FILTER_DEFAULT, | |
| 167 | + 'skudisp' => FILTER_DEFAULT, | |
| 168 | + 'skuunit' => FILTER_DEFAULT, | |
| 169 | + 'skugptekiyo' => FILTER_DEFAULT, | |
| 170 | + 'sort' => FILTER_DEFAULT, | |
| 171 | + 'skutaxrate' => FILTER_DEFAULT, | |
| 172 | + ); | |
| 173 | + | |
| 174 | + $inputs = filter_input_array( INPUT_POST, $args ); | |
| 175 | + | |
| 176 | + $skucprice = ( null !== $inputs['skucprice'] ) ? trim( $inputs['skucprice'] ) : 0; | |
| 177 | + $skuprice = ( null !== $inputs['skuprice'] ) ? trim( $inputs['skuprice'] ) : 0; | |
| 178 | + $skuzaikonum = ( null !== $inputs['skuzaikonum'] ) ? trim( $inputs['skuzaikonum'] ) : 0; | |
| 179 | + $skuzaiko = ( null !== $inputs['skuzaiko'] ) ? (int) $inputs['skuzaiko'] : ''; | |
| 180 | + $skudisp = ( null !== $inputs['skudisp'] ) ? trim( $inputs['skudisp'] ) : ''; | |
| 181 | + $skuunit = ( null !== $inputs['skuunit'] ) ? trim( $inputs['skuunit'] ) : ''; | |
| 182 | + $skugptekiyo = ( null !== $inputs['skugptekiyo'] ) ? (int) $inputs['skugptekiyo'] : 0; | |
| 183 | + $skusort = ( null !== $inputs['sort'] ) ? $inputs['sort'] : 0; | |
| 184 | + $skutaxrate = ( null !== $inputs['skutaxrate'] ) ? $inputs['skutaxrate'] : ''; | |
| 185 | + | |
| 186 | + $value['code'] = $skucode; | |
| 187 | + $value['name'] = $skudisp; | |
| 188 | + $value['cprice'] = $skucprice; | |
| 189 | + $value['price'] = $skuprice; | |
| 190 | + $value['unit'] = $skuunit; | |
| 191 | + $value['stocknum'] = $skuzaikonum; | |
| 192 | + $value['stock'] = $skuzaiko; | |
| 193 | + $value['gp'] = $skugptekiyo; | |
| 194 | + $value['sort'] = $skusort; | |
| 195 | + $value['taxrate'] = $skutaxrate; | |
| 196 | + | |
| 197 | + $value = $usces->stripslashes_deep_post( $value ); | |
| 198 | + | |
| 199 | + $skus = wel_get_skus( $post_id, 'meta_id', false ); | |
| 200 | + foreach ( $skus as $sku ) { | |
| 201 | + if ( (string) $sku['code'] === (string) $skucode && $sku['meta_id'] != $skumetaid ) { | |
| 202 | + return -1; | |
| 203 | + } | |
| 204 | + } | |
| 205 | + | |
| 206 | + $value = apply_filters( 'usces_filter_up_item_sku_meta_value', $value ); | |
| 207 | + | |
| 208 | + if ( ! WCUtils::is_blank( $skumetaid ) && ! WCUtils::is_blank( $skucode ) && ! WCUtils::is_blank( $skuprice ) ) { | |
| 209 | + | |
| 210 | + $res = wel_update_sku_data_by_id( $skumetaid, $post_id, $value ); | |
| 211 | + return $res; | |
| 212 | + | |
| 213 | + } else { | |
| 214 | + | |
| 215 | + return false; | |
| 216 | + } | |
| 217 | +} | |
| 218 | + | |
| 219 | +/** | |
| 220 | + * Delete Item SKU by ajax. | |
| 221 | + * Ajax response when SKU is deleted in the SKU block of the product registration screen. | |
| 222 | + * | |
| 223 | + * @since 2.3.3 | |
| 224 | + * @param string $post_ID Post ID. | |
| 225 | + * @return Result. | |
| 226 | + */ | |
| 227 | +function del_item_sku_meta( $post_ID ) { | |
| 228 | + global $wpdb, $usces; | |
| 229 | + | |
| 230 | + $post_id = (int) $post_ID; | |
| 231 | + $meta_id = filter_input( INPUT_POST, 'skumetaid', FILTER_VALIDATE_INT ); | |
| 232 | + | |
| 233 | + $res = apply_filters( 'usces_filter_before_del_item_sku_meta', false, $post_id, $meta_id ); | |
| 234 | + if ( false !== $res ) { | |
| 235 | + return $res; | |
| 236 | + } | |
| 237 | + | |
| 238 | + $res = wel_delete_sku_data_by_id( $meta_id, $post_id ); | |
| 239 | + | |
| 240 | + // Resort. | |
| 241 | + $skus = wel_get_skus( $post_id, 'meta_id', false ); | |
| 242 | + | |
| 243 | + if ( ! empty( $skus ) ) { | |
| 244 | + uasort( $skus, function($a, $b) { | |
| 245 | + return $a['sort'] <=> $b['sort']; | |
| 246 | + }); | |
| 247 | + | |
| 248 | + $i = 0; | |
| 249 | + foreach ( $skus as $sku ) { | |
| 250 | + $sku['sort'] = $i; | |
| 251 | + $meta_id = $sku['meta_id']; | |
| 252 | + wel_update_sku_data_by_id( $meta_id, $post_id, $sku ); | |
| 253 | + $i++; | |
| 254 | + } | |
| 255 | + } | |
| 256 | + return; | |
| 257 | +} | |
| 258 | + | |
| 259 | +/** | |
| 260 | + * List of Item SKUs. | |
| 261 | + * To generate a list of SKUs in the SKU block of the product registration screen. | |
| 262 | + * | |
| 263 | + * @since 2.3.3 | |
| 264 | + * @param string $skus All SKUs. | |
| 265 | + */ | |
| 266 | +function list_item_sku_meta( $skus ) { | |
| 267 | + | |
| 268 | + if ( empty( $skus ) ) { // Exit if no meta. | |
| 269 | + ?> | |
| 270 | + <table id="skulist-table" class="list" style="display: none;"> | |
| 271 | + <thead> | |
| 272 | + <tr> | |
| 273 | + <th class="hanldh" rowspan="2"> </th> | |
| 274 | + <th><?php esc_html_e( 'SKU code', 'usces' ); ?></th> | |
| 275 | + <th><?php echo apply_filters( 'usces_filter_listprice_label', __( 'normal price', 'usces' ), null, null ); ?>(<?php usces_crcode(); ?>)</th> | |
| 276 | + <th><?php echo apply_filters( 'usces_filter_sellingprice_label', __( 'Sale price', 'usces' ), null, null ); ?>(<?php usces_crcode(); ?>)</th> | |
| 277 | + <th><?php esc_html_e( 'stock', 'usces' ); ?></th> | |
| 278 | + <th><?php esc_html_e( 'stock status', 'usces' ); ?></th><?php echo apply_filters( 'usces_filter_sku_meta_title1', '' ); ?> | |
| 279 | + </tr> | |
| 280 | + </thead> | |
| 281 | + <tbody id="item-sku-list"> | |
| 282 | + <tr><td></td><td></td><td></td><td></td><td></td></tr> | |
| 283 | + </tbody> | |
| 284 | + </table> | |
| 285 | + <?php | |
| 286 | + } else { | |
| 287 | + ?> | |
| 288 | + <table id="skulist-table" class="list"> | |
| 289 | + <thead> | |
| 290 | + <tr> | |
| 291 | + <th class="hanldh" rowspan="2"> </th> | |
| 292 | + <th class="item-sku-key"><?php esc_html_e( 'SKU code', 'usces' ); ?></th> | |
| 293 | + <th class="item-sku-cprice"><?php echo apply_filters( 'usces_filter_listprice_label', __( 'normal price', 'usces' ), null, null ); ?>(<?php usces_crcode(); ?>)</th> | |
| 294 | + <th class="item-sku-price"><?php echo apply_filters( 'usces_filter_sellingprice_label', __( 'Sale price', 'usces' ), null, null ); ?>(<?php usces_crcode(); ?>)</th> | |
| 295 | + <th class="item-sku-zaikonum"><?php esc_html_e( 'stock', 'usces' ); ?></th> | |
| 296 | + <th class="item-sku-zaiko"><?php esc_html_e( 'stock status', 'usces' ); ?></th><?php echo apply_filters( 'usces_filter_sku_meta_title1', '' ); ?> | |
| 297 | + </tr> | |
| 298 | + <tr> | |
| 299 | + <th><?php esc_html_e( 'SKU display name ', 'usces' ); ?></th> | |
| 300 | + <th><?php esc_html_e( 'unit', 'usces' ); ?></th> | |
| 301 | + <?php | |
| 302 | + $advance_title = '<th colspan="2"> </th>'; | |
| 303 | + echo apply_filters( 'usces_filter_sku_meta_form_advance_title', $advance_title ); | |
| 304 | + ?> | |
| 305 | + <th><?php esc_html_e( 'Apply business package', 'usces' ); ?></th><?php echo apply_filters( 'usces_filter_sku_meta_title2', '' ); ?> | |
| 306 | + </tr> | |
| 307 | + </thead> | |
| 308 | + <tbody id="item-sku-list"> | |
| 309 | + <?php | |
| 310 | + foreach ( $skus as $sku ) { | |
| 311 | + echo _list_item_sku_meta_row( $sku ); | |
| 312 | + } | |
| 313 | + ?> | |
| 314 | + </tbody> | |
| 315 | + </table> | |
| 316 | + <?php | |
| 317 | + } | |
| 318 | +} | |
| 319 | + | |
| 320 | +/** | |
| 321 | + * Row of Item SKU List. | |
| 322 | + * To generate a list of SKUs in the SKU block of the product registration screen. | |
| 323 | + * | |
| 324 | + * @since 2.3.3 | |
| 325 | + * @param string $sku SKU. | |
| 326 | + */ | |
| 327 | +function _list_item_sku_meta_row( $sku ) { | |
| 328 | + $r = ''; | |
| 329 | + $style = ''; | |
| 330 | + | |
| 331 | + $key = $sku['code']; | |
| 332 | + $cprice = $sku['cprice']; | |
| 333 | + $price = $sku['price']; | |
| 334 | + $zaikonum = $sku['stocknum']; | |
| 335 | + $zaiko = $sku['stock']; | |
| 336 | + $skudisp = $sku['name']; | |
| 337 | + $skuunit = $sku['unit']; | |
| 338 | + $skugptekiyo = $sku['gp']; | |
| 339 | + $id = (int) $sku['meta_id']; | |
| 340 | + $zaikoselectarray = get_option( 'usces_zaiko_status', array() ); | |
| 341 | + $zaikoselectarray = apply_filters( 'usces_filter_zaikoselectarray', $zaikoselectarray ); | |
| 342 | + $zaikoselect_count = ( $zaikoselectarray && is_array( $zaikoselectarray ) ) ? count( $zaikoselectarray ) : 0; | |
| 343 | + $sort = (int) $sku['sort']; | |
| 344 | + $sku_colspan = apply_filters( 'usces_filter_sku_meta_colspan', '6' ); | |
| 345 | + | |
| 346 | + ob_start(); | |
| 347 | + ?> | |
| 348 | + <tr class="metastuffrow"><td colspan="<?php echo esc_attr( $sku_colspan ); ?>"> | |
| 349 | + <table id="itemsku-<?php echo esc_attr( $id ); ?>" class="metastufftable"> | |
| 350 | + <tr> | |
| 351 | + <th class="handlb" rowspan="<?php echo apply_filters( 'usces_filter_sku_meta_rowspan', '3' ); ?>"> </th> | |
| 352 | + <td class="item-sku-key"><input name="itemsku[<?php echo esc_attr( $id ); ?>][key]" id="itemsku[<?php echo esc_attr( $id ); ?>][key]" class="skuname metaboxfield" type="text" value="<?php echo esc_attr( $key ); ?>" /></td> | |
| 353 | + <td class="item-sku-cprice"><input name="itemsku[<?php echo esc_attr( $id ); ?>][cprice]" id="itemsku[<?php echo esc_attr( $id ); ?>][cprice]" class="skuprice metaboxfield" type="text" value="<?php echo esc_attr( $cprice ); ?>" /></td> | |
| 354 | + <td class="item-sku-price"><input name="itemsku[<?php echo esc_attr( $id ); ?>][price]" id="itemsku[<?php echo esc_attr( $id ); ?>][price]" class="skuprice metaboxfield" type="text" value="<?php echo esc_attr( $price ); ?>" /></td> | |
| 355 | + <td class="item-sku-zaikonum"><input name="itemsku[<?php echo esc_attr( $id ); ?>][zaikonum]" id="itemsku[<?php echo esc_attr( $id ); ?>][zaikonum]" class="skuzaikonum metaboxfield" type="text" value="<?php echo esc_attr( $zaikonum ); ?>" /></td> | |
| 356 | + <td class="item-sku-zaiko"> | |
| 357 | + <select id="itemsku[<?php echo esc_attr( $id ); ?>][zaiko]" name="itemsku[<?php echo esc_attr( $id ); ?>][zaiko]" class="skuzaiko metaboxfield"> | |
| 358 | + <?php | |
| 359 | + for ( $i = 0; $i < $zaikoselect_count; $i++ ) { | |
| 360 | + ?> | |
| 361 | + <option value="<?php echo esc_attr( $i ); ?>"<?php selected( $zaiko, $i ); ?>><?php echo esc_attr( $zaikoselectarray[ $i ] ); ?></option> | |
| 362 | + <?php | |
| 363 | + } | |
| 364 | + ?> | |
| 365 | + </select> | |
| 366 | + </td><?php echo apply_filters( 'usces_filter_sku_meta_field1', '', $sku ); ?> | |
| 367 | + </tr> | |
| 368 | + <tr> | |
| 369 | + <td class="item-sku-key"><input name="itemsku[<?php echo esc_attr( $id ); ?>][skudisp]" id="itemsku[<?php echo esc_attr( $id ); ?>][skudisp]" class="skudisp metaboxfield" type="text" value="<?php echo esc_attr( $skudisp ); ?>" /> | |
| 370 | + </td> | |
| 371 | + <td class="item-sku-cprice"><input name="itemsku[<?php echo esc_attr( $id ); ?>][skuunit]" id="itemsku[<?php echo esc_attr( $id ); ?>][skuunit]" class="skuunit metaboxfield" type="text" value="<?php echo esc_attr( $skuunit ); ?>" /></td> | |
| 372 | + <?php | |
| 373 | + $default_field = "\n\t\t" . '<td colspan="2"> </td>'; | |
| 374 | + echo apply_filters( 'usces_filter_sku_meta_row_advance', $default_field, $sku ); | |
| 375 | + ?> | |
| 376 | + <td class="item-sku-zaiko"> | |
| 377 | + <select id="itemsku[<?php echo esc_attr( $id ); ?>][skugptekiyo]" name="itemsku[<?php echo esc_attr( $id ); ?>][skugptekiyo]" class="skugptekiyo metaboxfield"> | |
| 378 | + <option value="0"<?php selected( $skugptekiyo, 0 ); ?>><?php esc_html_e( 'Not apply', 'usces' ); ?></option> | |
| 379 | + <option value="1"<?php selected( $skugptekiyo, 1 ); ?>><?php esc_html_e( 'Apply', 'usces' ); ?></option> | |
| 380 | + </select> | |
| 381 | + </td><?php echo apply_filters( 'usces_filter_sku_meta_field2', '', $sku ); ?> | |
| 382 | + </tr> | |
| 383 | + <?php echo apply_filters( 'usces_filter_sku_meta_row', '', $sku ); ?> | |
| 384 | + <tr> | |
| 385 | + <td colspan="<?php echo esc_attr( $sku_colspan - 1 ); ?>" class="submittd"> | |
| 386 | + <div id="skusubmit-<?php echo esc_attr( $id ); ?>" class="submit"> | |
| 387 | + <input name="deleteitemsku[<?php echo esc_attr( $id ); ?>]" id="deleteitemsku[<?php echo esc_attr( $id ); ?>]" type="button" class="button" value="<?php esc_attr_e( 'Delete' ); ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('deleteitemsku', <?php echo esc_attr( $id ); ?>);" /> | |
| 388 | + <input name="updateitemsku[<?php echo esc_attr( $id ); ?>]" id="updateitemsku[<?php echo esc_attr( $id ); ?>]" type="button" class="button" value="<?php esc_attr_e( 'Update' ); ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemSku.post('updateitemsku', <?php echo esc_attr( $id ); ?>);" /> | |
| 389 | + <input name="itemsku[<?php echo esc_attr( $id ); ?>][sort]" id="itemsku[<?php echo esc_attr( $id ); ?>][sort]" type="hidden" value="<?php echo esc_attr( $sort ); ?>" /> | |
| 390 | + <?php usces_sku_meta_row_reduced_taxrate( $sku ); ?> | |
| 391 | + </div> | |
| 392 | + <div id="itemsku_loading-<?php echo esc_attr( $id ); ?>" class="meta_submit_loading"></div> | |
| 393 | + </td> | |
| 394 | + </tr> | |
| 395 | + </table> | |
| 396 | + </td></tr> | |
| 397 | + <?php | |
| 398 | + $r = ob_get_contents(); | |
| 399 | + ob_end_clean(); | |
| 400 | + return $r; | |
| 401 | +} | |
| 402 | + | |
| 403 | +/** | |
| 404 | + * New SKU Form. | |
| 405 | + * The form to add a new SKU in the SKU block on the product registration screen. | |
| 406 | + * | |
| 407 | + * @since 2.3.3 | |
| 408 | + */ | |
| 409 | +function item_sku_meta_form() { | |
| 410 | + $sku_colspan = apply_filters( 'usces_filter_sku_meta_colspan', '6' ); | |
| 411 | + ?> | |
| 412 | + <div id="sku_ajax-response"></div> | |
| 413 | + <p><strong><?php esc_html_e( 'Add new SKU', 'usces' ); ?> : </strong></p> | |
| 414 | + <table id="newsku"> | |
| 415 | + <thead> | |
| 416 | + <tr> | |
| 417 | + <th class="left"><?php esc_html_e( 'SKU code', 'usces' ); ?></th> | |
| 418 | + <th><?php echo apply_filters( 'usces_filter_listprice_label', __( 'normal price', 'usces' ), null, null ); ?>(<?php usces_crcode(); ?>)</th> | |
| 419 | + <th><?php echo apply_filters( 'usces_filter_sellingprice_label', __( 'Sale price', 'usces' ), null, null ); ?>(<?php usces_crcode(); ?>)</th> | |
| 420 | + <th><?php esc_html_e( 'stock', 'usces' ); ?></th> | |
| 421 | + <th><?php esc_html_e( 'stock status', 'usces' ); ?></th><?php echo apply_filters( 'usces_filter_sku_meta_title1', '' ); ?> | |
| 422 | + </tr> | |
| 423 | + <tr> | |
| 424 | + <th><?php esc_html_e( 'SKU display name ', 'usces' ); ?></th> | |
| 425 | + <th><?php esc_html_e( 'unit', 'usces' ); ?></th> | |
| 426 | + <?php | |
| 427 | + $advance_title = '<th colspan="2"> </th>'; | |
| 428 | + echo apply_filters( 'usces_filter_sku_meta_form_advance_title', $advance_title ); | |
| 429 | + ?> | |
| 430 | + <th><?php esc_html_e( 'Apply business package', 'usces' ); ?></th><?php echo apply_filters( 'usces_filter_sku_meta_title2', '' ); ?> | |
| 431 | + </tr> | |
| 432 | + </thead> | |
| 433 | + <tbody> | |
| 434 | + <tr> | |
| 435 | + <td id="newskuleft" class="item-sku-key"><input type="text" id="newskuname" name="newskuname" class="newskuname metaboxfield" value="" /></td> | |
| 436 | + <td class="item-sku-cprice"><input type="text" id="newskucprice" name="newskucprice" class="newskuprice metaboxfield" /></td> | |
| 437 | + <td class="item-sku-price"><input type="text" id="newskuprice" name="newskuprice" class="newskuprice metaboxfield" /></td> | |
| 438 | + <td class="item-sku-zaikonum"><input type="text" id="newskuzaikonum" name="newskuzaikonum" class="newskuzaikonum metaboxfield" /></td> | |
| 439 | + <td class="item-sku-zaiko"> | |
| 440 | + <select id="newskuzaikoselect" name="newskuzaikoselect" class="newskuzaikoselect metaboxfield"> | |
| 441 | + <?php | |
| 442 | + $zaikoselectarray = get_option( 'usces_zaiko_status', array() ); | |
| 443 | + foreach ( $zaikoselectarray as $v => $l ) { | |
| 444 | + echo "\n" . '<option value="' . esc_attr( $v ) . '">' . esc_html( $l ) . '</option>'; | |
| 445 | + } | |
| 446 | + ?> | |
| 447 | + </select> | |
| 448 | + </td><?php echo apply_filters( 'usces_filter_newsku_meta_field1', '' ); ?> | |
| 449 | + </tr> | |
| 450 | + <tr> | |
| 451 | + <td class="item-sku-key"><input type="text" id="newskudisp" name="newskudisp" class="newskudisp metaboxfield" /></td> | |
| 452 | + <td class="item-sku-cprice"><input type="text" id="newskuunit" name="newskuunit" class="newskuunit metaboxfield" /></td> | |
| 453 | + <?php | |
| 454 | + $advance_field = '<td class="item-sku-price"> </td><td class="item-sku-zaikonum"> </td>'; | |
| 455 | + echo apply_filters( 'usces_filter_sku_meta_form_advance_field', $advance_field ); | |
| 456 | + ?> | |
| 457 | + <td class="item-sku-zaiko"> | |
| 458 | + <select id="newskugptekiyo" name="newskugptekiyo" class="newskugptekiyo metaboxfield"> | |
| 459 | + <option value="0"><?php esc_html_e( 'Not apply', 'usces' ); ?></option> | |
| 460 | + <option value="1"><?php esc_html_e( 'Apply', 'usces' ); ?></option> | |
| 461 | + </select> | |
| 462 | + </td><?php echo apply_filters( 'usces_filter_newsku_meta_field2', '' ); ?> | |
| 463 | + </tr> | |
| 464 | + <?php echo apply_filters( 'usces_filter_newsku_meta_row', '' ); ?> | |
| 465 | + <tr> | |
| 466 | + <td colspan="<?php echo esc_attr( $sku_colspan - 1 ); ?>" class="submittd"> | |
| 467 | + <div id="newskusubmit" class="submit"> | |
| 468 | + <?php | |
| 469 | + $add_itemsku_button = '<input name="add_itemsku" type="button" class="button" id="add_itemsku" tabindex="9" value="' . esc_html__( 'Add SKU', 'usces' ) . '" onclick="if( jQuery(\'#post_ID\').val() < 0 ) return; itemSku.post(\'additemsku\', 0);" />'; | |
| 470 | + echo apply_filters( 'usces_filter_newsku_meta_add_button', $add_itemsku_button ); | |
| 471 | + ?> | |
| 472 | + <?php usces_newsku_meta_row_reduced_taxrate(); ?> | |
| 473 | + </div> | |
| 474 | + <div id="newitemsku_loading" class="meta_submit_loading"></div> | |
| 475 | + </td> | |
| 476 | + </tr> | |
| 477 | + </tbody> | |
| 478 | + </table> | |
| 479 | + <?php | |
| 480 | +} | |
| 481 | + | |
| 482 | +/** | |
| 483 | + * Get Post Meta using MetaID. | |
| 484 | + * | |
| 485 | + * @since 2.3.3 | |
| 486 | + * @param int $meta_id Meta ID. | |
| 487 | + * @return MetaData|false | |
| 488 | + */ | |
| 489 | +function usces_get_post_meta_by_metaid( $meta_id ) { | |
| 490 | + global $wpdb; | |
| 491 | + | |
| 492 | + $res = $wpdb->get_row( | |
| 493 | + $wpdb->prepare( | |
| 494 | + "SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", | |
| 495 | + $meta_id | |
| 496 | + ), | |
| 497 | + ARRAY_A | |
| 498 | + ); | |
| 499 | + return $res; | |
| 500 | +} | |
| 501 | + | |
| 502 | +/** | |
| 503 | + * Get Post meta. | |
| 504 | + * Get product metadata by specifying meta_key. | |
| 505 | + * | |
| 506 | + * @since 2.3.3 | |
| 507 | + * @param string $post_id Post ID. | |
| 508 | + * @param string $key Meta key. | |
| 509 | + * @param boolean $cache Switch of cache. | |
| 510 | + * @return MetaData|false | |
| 511 | + */ | |
| 512 | +function usces_get_post_meta( $post_id, $key, $cache = true ) { | |
| 513 | + global $wpdb; | |
| 514 | + | |
| 515 | + $cache_key = 'wel_post_meta_' . $post_id . '_' . $key; | |
| 516 | + if ( true === $cache ) { | |
| 517 | + $meta_data = wp_cache_get( $cache_key ); | |
| 518 | + } else { | |
| 519 | + $meta_data = false; | |
| 520 | + } | |
| 521 | + if ( false === $meta_data || is_admin() || wp_doing_ajax() ) { | |
| 522 | + $meta_data = $wpdb->get_results( | |
| 523 | + $wpdb->prepare( | |
| 524 | + "SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", | |
| 525 | + $post_id, | |
| 526 | + $key | |
| 527 | + ), | |
| 528 | + ARRAY_A | |
| 529 | + ); | |
| 530 | + if ( null !== $meta_data ) { | |
| 531 | + wp_cache_set( $cache_key, $meta_data ); | |
| 532 | + } | |
| 533 | + } | |
| 534 | + | |
| 535 | + if ( null === $meta_data ) { | |
| 536 | + return false; | |
| 537 | + } else { | |
| 538 | + return $meta_data; | |
| 539 | + } | |
| 540 | +} | |
| 541 | + | |
| 542 | +/** | |
| 543 | + * Sort Options. | |
| 544 | + * Ajax response when changing the order of optios in the SKU block of the product registration screen. | |
| 545 | + * | |
| 546 | + * @since 2.3.3 | |
| 547 | + * @param int $post_id Post ID. | |
| 548 | + * @param int $metastr Meta ids. | |
| 549 | + */ | |
| 550 | +function usces_sort_item_opts( $post_id, $metastr ) { | |
| 551 | + global $wpdb; | |
| 552 | + | |
| 553 | + $meta_ids = explode( ',', $metastr ); | |
| 554 | + $opts = wel_get_opts( $post_id, 'meta_id', false ); | |
| 555 | + | |
| 556 | + if ( ! empty( $meta_ids ) ) { | |
| 557 | + | |
| 558 | + $i = 0; | |
| 559 | + foreach ( $meta_ids as $meta_id ) { | |
| 560 | + | |
| 561 | + $opt = $opts[ $meta_id ]; | |
| 562 | + $opt['sort'] = $i; | |
| 563 | + | |
| 564 | + wel_update_opt_data_by_id( $meta_id, $post_id, $opt ); | |
| 565 | + | |
| 566 | + $i++; | |
| 567 | + } | |
| 568 | + } | |
| 569 | +} | |
| 570 | + | |
| 571 | +/** | |
| 572 | + * Sort SKUs. | |
| 573 | + * Ajax response when changing the order of SKUs in the SKU block of the product registration screen. | |
| 574 | + * | |
| 575 | + * @since 2.3.3 | |
| 576 | + * @param int $post_id Post ID. | |
| 577 | + * @param int $metastr Meta ids. | |
| 578 | + */ | |
| 579 | +function usces_sort_item_skus( $post_id, $metastr ) { | |
| 580 | + global $wpdb; | |
| 581 | + | |
| 582 | + $meta_ids = explode( ',', $metastr ); | |
| 583 | + $skus = wel_get_skus( $post_id, 'meta_id', false ); | |
| 584 | + | |
| 585 | + if ( ! empty( $meta_ids ) ) { | |
| 586 | + | |
| 587 | + $i = 0; | |
| 588 | + foreach ( $meta_ids as $meta_id ) { | |
| 589 | + | |
| 590 | + $i = 0; | |
| 591 | + foreach ( $meta_ids as $meta_id ) { | |
| 592 | + | |
| 593 | + $sku = $skus[ $meta_id ]; | |
| 594 | + $sku['sort'] = $i; | |
| 595 | + | |
| 596 | + wel_update_sku_data_by_id( $meta_id, $post_id, $sku ); | |
| 597 | + | |
| 598 | + $i++; | |
| 599 | + } | |
| 600 | + } | |
| 601 | + } | |
| 602 | +} | |
| 603 | + | |
| 604 | +/** | |
| 605 | + * Get all options by post id. | |
| 606 | + * | |
| 607 | + * @since 2.3.3 | |
| 608 | + * @param int $post_id Post ID. | |
| 609 | + * @param string $keyflag Sort key. | |
| 610 | + * @param bool $cache Cache. | |
| 611 | + */ | |
| 612 | +function usces_get_opts( $post_id, $keyflag = 'sort', $cache = true ) { | |
| 613 | + $opts = wel_get_opts( $post_id, $keyflag, $cache ); | |
| 614 | + return $opts; | |
| 615 | +} | |
| 616 | + | |
| 617 | +/** | |
| 618 | + * Add Item Option. | |
| 619 | + * | |
| 620 | + * @since 2.3.3 | |
| 621 | + * @param string $post_id Post ID. | |
| 622 | + * @param string $new_value SKU data. | |
| 623 | + * @param boolean $check Switch of check. | |
| 624 | + * @return New meta id. | |
| 625 | + */ | |
| 626 | +function usces_add_opt( $post_id, $new_value, $check = true ) { | |
| 627 | + global $wpdb, $usces; | |
| 628 | + | |
| 629 | + if ( $check ) { | |
| 630 | + | |
| 631 | + $opts = wel_get_opts( $post_id, 'meta_id', false ); | |
| 632 | + | |
| 633 | + if ( ! empty( $opts ) && is_array( $opts ) ) { | |
| 634 | + | |
| 635 | + $meta_num = count( $opts ); | |
| 636 | + $unique = true; | |
| 637 | + $sortnull = true; | |
| 638 | + $sort = array(); | |
| 639 | + | |
| 640 | + foreach ( (array) $opts as $opt ) { | |
| 641 | + | |
| 642 | + if ( $opt['name'] === $new_value['name'] ) { | |
| 643 | + $unique = false; | |
| 644 | + } | |
| 645 | + if ( ! isset( $opt['sort'] ) ) { | |
| 646 | + $sortnull = false; | |
| 647 | + } | |
| 648 | + $sort[] = $opt['sort']; | |
| 649 | + } | |
| 650 | + | |
| 651 | + if ( ! $unique ) { | |
| 652 | + return -1; | |
| 653 | + } | |
| 654 | + | |
| 655 | + rsort( $sort ); | |
| 656 | + $next_number = reset( $sort ) + 1; | |
| 657 | + $unique_sort = array_unique( $sort ); | |
| 658 | + if ( $meta_num !== count( $unique_sort ) || $meta_num !== $next_number || ! $sortnull ) { | |
| 659 | + // To repair the sort data. | |
| 660 | + $i = 0; | |
| 661 | + foreach ( (array) $opts as $opt ) { | |
| 662 | + $opt['sort'] = $i; | |
| 663 | + wel_update_opt_data_by_id( $opt['meta_id'], $post_id, $opt ); | |
| 664 | + $i++; | |
| 665 | + } | |
| 666 | + } | |
| 667 | + } | |
| 668 | + | |
| 669 | + $new_value['sort'] = ! empty( $meta_num ) ? $meta_num : 0; | |
| 670 | + } | |
| 671 | + | |
| 672 | + $id = wel_add_opt_data( $post_id, $new_value ); | |
| 673 | + return $id; | |
| 674 | +} | |
| 675 | + | |
| 676 | +/** | |
| 677 | + * List item option | |
| 678 | + * | |
| 679 | + * @param array $opts Options. | |
| 680 | + */ | |
| 681 | +function list_item_option_meta( $opts ) { | |
| 682 | + // Exit if no meta. | |
| 683 | + if ( ! $opts ) { | |
| 684 | + ?> | |
| 685 | + <table id="optlist-table" class="list" style="display: none;"> | |
| 686 | + <thead> | |
| 687 | + <tr> | |
| 688 | + <th class="hanldh"> </th> | |
| 689 | + <th class="item-opt-key"><?php esc_html_e( 'option name', 'usces' ); ?></th> | |
| 690 | + <th class="item-opt-value"><?php esc_html_e( 'selected amount', 'usces' ); ?></th> | |
| 691 | + </tr> | |
| 692 | + </thead> | |
| 693 | + <tbody id="item-opt-list"> | |
| 694 | + <tr><td></td></tr> | |
| 695 | + </tbody> | |
| 696 | + </table> | |
| 697 | + <?php | |
| 698 | + } else { | |
| 699 | + ?> | |
| 700 | + <table id="optlist-table" class="list"> | |
| 701 | + <thead> | |
| 702 | + <tr> | |
| 703 | + <th class="hanldh"> </th> | |
| 704 | + <th class="item-opt-key"><?php esc_html_e( 'option name', 'usces' ); ?></th> | |
| 705 | + <th class="item-opt-value"><?php esc_html_e( 'selected amount', 'usces' ); ?></th> | |
| 706 | + </tr> | |
| 707 | + </thead> | |
| 708 | + <tbody id="item-opt-list"> | |
| 709 | + <?php | |
| 710 | + foreach ( $opts as $opt ) { | |
| 711 | + echo _list_item_option_meta_row( $opt ); | |
| 712 | + } | |
| 713 | + ?> | |
| 714 | + </tbody> | |
| 715 | + </table> | |
| 716 | + <?php | |
| 717 | + } | |
| 718 | +} | |
| 719 | + | |
| 720 | +/** | |
| 721 | + * Option meta row | |
| 722 | + * | |
| 723 | + * @param array $opt Options. | |
| 724 | + */ | |
| 725 | +function _list_item_option_meta_row( $opt ) { | |
| 726 | + $r = ''; | |
| 727 | + $style = ''; | |
| 728 | + $means = get_option( 'usces_item_option_select', array() ); | |
| 729 | + | |
| 730 | + $name = $opt['name']; | |
| 731 | + $meansoption = ''; | |
| 732 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 733 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '"' . selected( $meankey, $opt['means'], false ) . '>' . esc_html( $meanvalue ) . "</option>\n"; | |
| 734 | + } | |
| 735 | + $essential = ( 1 === (int) $opt['essential'] ) ? ' checked="checked"' : ''; | |
| 736 | + $value = ''; | |
| 737 | + if ( is_array( $opt['value'] ) ) { | |
| 738 | + foreach ( $opt['value'] as $k => $v ) { | |
| 739 | + $value .= $v . "\n"; | |
| 740 | + } | |
| 741 | + } else { | |
| 742 | + $value = $opt['value']; | |
| 743 | + } | |
| 744 | + $value = trim( $value ); | |
| 745 | + $id = (int) $opt['meta_id']; | |
| 746 | + $sort = (int) $opt['sort']; | |
| 747 | + | |
| 748 | + ob_start(); | |
| 749 | + ?> | |
| 750 | + <tr class="metastuffrow"><td colspan="3"> | |
| 751 | + <table id="itemopt-<?php echo esc_attr( $id ); ?>" class="metastufftable"> | |
| 752 | + <tr> | |
| 753 | + <th class="handlb" rowspan="2"> </th> | |
| 754 | + <td class="item-opt-key"> | |
| 755 | + <div><input name="itemopt[<?php echo esc_attr( $id ); ?>][name]" id="itemopt[<?php echo esc_attr( $id ); ?>][name]" class="metaboxfield" type="text" size="20" value="<?php echo esc_attr( $name ); ?>" /></div> | |
| 756 | + <div class="optcheck"> | |
| 757 | + <select name="itemopt[<?php echo esc_attr( $id ); ?>][means]" id="itemopt[<?php echo esc_attr( $id ); ?>][means]"><?php wel_esc_script_e( $meansoption ); ?></select> | |
| 758 | + <label for="itemopt[<?php echo esc_attr( $id ); ?>][essential]"><input name="itemopt[<?php echo esc_attr( $id ); ?>][essential]" id="itemopt[<?php echo esc_attr( $id ); ?>][essential]" type="checkbox" value="1"<?php echo esc_attr( $essential ); ?> class="metaboxcheckfield" /><?php esc_html_e( 'Required','usces' ); ?></label> | |
| 759 | + </div> | |
| 760 | + </td> | |
| 761 | + <td class="item-opt-value"> | |
| 762 | + <textarea name="itemopt[<?php echo esc_attr( $id ); ?>][value]" id="itemopt[<?php echo esc_attr( $id ); ?>][value]" class="metaboxfield"><?php echo esc_html( $value ); ?></textarea> | |
| 763 | + </td> | |
| 764 | + </tr> | |
| 765 | + <tr> | |
| 766 | + <td colspan="2" class="submittd"> | |
| 767 | + <div id="itemoptsubmit-<?php echo esc_attr( $id ); ?>" class="submit"> | |
| 768 | + <input name="deleteitemopt[<?php echo esc_attr( $id ); ?>]" id="deleteitemopt[<?php echo esc_attr( $id ); ?>]" type="button" class="button" value="<?php esc_attr_e( 'Delete' ); ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('deleteitemopt', <?php echo esc_attr( $id ); ?>);" /> | |
| 769 | + <input name="updateitemopt[<?php echo esc_attr( $id ); ?>]" id="updateitemopt[<?php echo esc_attr( $id ); ?>]" type="button" class="button" value="<?php esc_attr_e( 'Update' ); ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('updateitemopt', <?php echo esc_attr( $id ); ?>);" /> | |
| 770 | + <input name="itemopt[<?php echo esc_attr( $id ); ?>][sort]" id="itemopt[<?php echo esc_attr( $id ); ?>][sort]" type="hidden" value="<?php echo esc_attr( $sort ); ?>" /> | |
| 771 | + </div> | |
| 772 | + <div id="itemopt_loading-<?php echo esc_attr( $id ); ?>" class="meta_submit_loading"></div> | |
| 773 | + </td> | |
| 774 | + </tr> | |
| 775 | + </table> | |
| 776 | + </td></tr> | |
| 777 | + <?php | |
| 778 | + $r = ob_get_contents(); | |
| 779 | + ob_end_clean(); | |
| 780 | + return $r; | |
| 781 | +} | |
| 782 | + | |
| 783 | +/** | |
| 784 | + * Common option meta form | |
| 785 | + */ | |
| 786 | +function common_option_meta_form() { | |
| 787 | + $means = get_option( 'usces_item_option_select', array() ); | |
| 788 | + $meansoption = ''; | |
| 789 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 790 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '">' . esc_html( $meanvalue ) . "</option>\n"; | |
| 791 | + } | |
| 792 | + ?> | |
| 793 | + <div id="itemopt_ajax-response"></div> | |
| 794 | + <p><strong><?php esc_html_e( 'Add a new option', 'usces' ); ?> : </strong></p> | |
| 795 | + <table id="newmeta2"> | |
| 796 | + <thead> | |
| 797 | + <tr> | |
| 798 | + <th class="left"><label for="metakeyselect"><?php esc_html_e( 'option name', 'usces' ); ?></label></th> | |
| 799 | + <th><label for="metavalue"><?php esc_html_e( 'selected amount', 'usces' ); ?></label></th> | |
| 800 | + </tr> | |
| 801 | + </thead> | |
| 802 | + <tbody> | |
| 803 | + <tr> | |
| 804 | + <td class="item-opt-key"> | |
| 805 | + <input type="text" id="newoptname" name="newoptname" class="metaboxfield" tabindex="7" value="" /> | |
| 806 | + <div class="optcheck"> | |
| 807 | + <select name="newoptmeans" id="newoptmeans" class="metaboxfield long"><?php wel_esc_script_e( $meansoption ); ?></select> | |
| 808 | + <label for="newoptessential"><input name="newoptessential" type="checkbox" id="newoptessential" class="metaboxcheckfield" /><?php esc_html_e( 'Required', 'usces' ); ?></label> | |
| 809 | + </div> | |
| 810 | + </td> | |
| 811 | + <td class="item-opt-value"><textarea id="newoptvalue" name="newoptvalue" class="metaboxfield"></textarea></td> | |
| 812 | + </tr> | |
| 813 | + <tr> | |
| 814 | + <td colspan="2" class="submittd"> | |
| 815 | + <div id="newcomoptsubmit" class="submit"> | |
| 816 | + <input name="add_comopt" type="button" class="button" id="add_comopt" tabindex="9" value="<?php esc_attr_e( 'Add common options', 'usces' ); ?>" onclick="itemOpt.post('addcommonopt', 0);" /> | |
| 817 | + </div> | |
| 818 | + <div id="newcomopt_loading" class="meta_submit_loading"></div> | |
| 819 | + </td> | |
| 820 | + </tr> | |
| 821 | + </tbody> | |
| 822 | + </table> | |
| 823 | + <?php | |
| 824 | +} | |
| 825 | + | |
| 826 | +/** | |
| 827 | + * Item option meta form | |
| 828 | + */ | |
| 829 | +function item_option_meta_form() { | |
| 830 | + $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); | |
| 831 | + $cart_number = (int) get_option( 'usces_cart_number' ); | |
| 832 | + $opts = usces_get_opts( $cart_number ); | |
| 833 | + $means = get_option( 'usces_item_option_select', array() ); | |
| 834 | + $meansoption = ''; | |
| 835 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 836 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '">' . esc_html( $meanvalue ) . "</option>\n"; | |
| 837 | + } | |
| 838 | + ?> | |
| 839 | + <div id="itemopt_ajax-response"></div> | |
| 840 | + <p><strong><?php esc_html_e( 'Applicable product options', 'usces' ); ?> : </strong></p> | |
| 841 | + <table id="newmeta2"> | |
| 842 | + <thead> | |
| 843 | + <tr> | |
| 844 | + <th class="item-opt-key"><label for="metakeyselect"><?php esc_html_e( 'option name', 'usces' ); ?></label></th> | |
| 845 | + <th class="item-opt-value"><label for="metavalue"><?php esc_html_e( 'selected amount', 'usces' ); ?></label></th> | |
| 846 | + </tr> | |
| 847 | + </thead> | |
| 848 | + <tbody> | |
| 849 | + <tr> | |
| 850 | + <td class='item-opt-key'> | |
| 851 | + <?php if ( ! empty( $opts ) ) { ?> | |
| 852 | + <select id="optkeyselect" name="optkeyselect" class="optkeyselect metaboxfield" tabindex="7" onchange="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('keyselect', this.value);"> | |
| 853 | + <option value="#NONE#"><?php esc_html_e( '-- Select --', 'usces' ); ?></option> | |
| 854 | + <?php foreach ( $opts as $opt ) { ?> | |
| 855 | + <option value="<?php echo esc_attr( $opt['meta_id'] ); ?>"><?php echo esc_attr( $opt['name'] ); ?></option> | |
| 856 | + <?php } ?> | |
| 857 | + </select> | |
| 858 | + <input type="hidden" id="newoptname" name="newoptname" class="metaboxfield" /> | |
| 859 | + <div class="optcheck"> | |
| 860 | + <select name="newoptmeans" id="newoptmeans"><?php wel_esc_script_e( $meansoption ); ?></select> | |
| 861 | + <label for="newoptessential"><input name="newoptessential" type="checkbox" id="newoptessential" class="metaboxcheckfield" /><?php esc_html_e( 'Required', 'usces' ); ?></label> | |
| 862 | + </div> | |
| 863 | + <?php } else { ?> | |
| 864 | + <p><?php esc_html_e( 'Please create a common option.', 'usces' ); ?></p> | |
| 865 | + <?php } ?> | |
| 866 | + </td> | |
| 867 | + <td class="item-opt-value"><textarea id="newoptvalue" name="newoptvalue" class="metaboxfield"></textarea></td> | |
| 868 | + </tr> | |
| 869 | + <tr> | |
| 870 | + <td colspan="2" class="submittd"> | |
| 871 | + <?php if ( is_array( $opts ) ) { ?> | |
| 872 | + <div id="newitemoptsubmit" class="submit"> | |
| 873 | + <input name="add_itemopt" type="button" class='button' id="add_itemopt" tabindex="9" value="<?php esc_attr_e( 'Apply an option', 'usces' ); ?>" onclick="if( jQuery('#post_ID').val() < 0 ) return; itemOpt.post('additemopt', 0);" /> | |
| 874 | + </div> | |
| 875 | + <div id="newitemopt_loading" class="meta_submit_loading"></div> | |
| 876 | + <?php } ?> | |
| 877 | + </td> | |
| 878 | + </tr> | |
| 879 | + </tbody> | |
| 880 | + </table> | |
| 881 | + <?php | |
| 882 | +} | |
| 883 | + | |
| 884 | +/** | |
| 885 | + * Add item option meta | |
| 886 | + * | |
| 887 | + * @param int $post_ID Post ID. | |
| 888 | + * @return mixed | |
| 889 | + */ | |
| 890 | +function add_item_option_meta( $post_ID ) { | |
| 891 | + global $usces; | |
| 892 | + | |
| 893 | + $post_id = (int) $post_ID; | |
| 894 | + $value = array(); | |
| 895 | + $opts = array(); | |
| 896 | + $protected = array( | |
| 897 | + '#NONE#', | |
| 898 | + '_wp_attached_file', | |
| 899 | + '_wp_attachment_metadata', | |
| 900 | + '_wp_old_slug', | |
| 901 | + '_wp_page_template', | |
| 902 | + ); | |
| 903 | + | |
| 904 | + $args = array( | |
| 905 | + 'newoptcode' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 906 | + 'newoptname' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 907 | + 'newoptmeans' => array( | |
| 908 | + 'filter' => FILTER_VALIDATE_INT, | |
| 909 | + 'flags' => FILTER_REQUIRE_SCALAR, | |
| 910 | + 'options' => array( 'defalut' => 0 ), | |
| 911 | + ), | |
| 912 | + 'newoptessential' => array( | |
| 913 | + 'filter' => FILTER_VALIDATE_INT, | |
| 914 | + 'flags' => FILTER_REQUIRE_SCALAR, | |
| 915 | + 'options' => array( 'defalut' => 0 ), | |
| 916 | + ), | |
| 917 | + 'newoptvalue' => FILTER_DEFAULT, | |
| 918 | + ); | |
| 919 | + $inputs = filter_input_array( INPUT_POST, $args ); | |
| 920 | + $newoptcode = $inputs['newoptcode']; | |
| 921 | + $newoptname = $inputs['newoptname']; | |
| 922 | + $newoptmeans = $inputs['newoptmeans']; | |
| 923 | + $newoptessential = $inputs['newoptessential']; | |
| 924 | + $newoptvalue = $inputs['newoptvalue']; | |
| 925 | + | |
| 926 | + if ( ( $newoptmeans >= 2 || WCUtils::is_zero( $newoptvalue ) || ! empty ( $newoptvalue ) ) && ! empty ( $newoptname ) ) { | |
| 927 | + | |
| 928 | + if ( $newoptname ) { | |
| 929 | + $metakey = $newoptname; // default. | |
| 930 | + } | |
| 931 | + | |
| 932 | + if ( in_array( $metakey, $protected ) ) { | |
| 933 | + return false; | |
| 934 | + } | |
| 935 | + | |
| 936 | + $WelItem = new Welcart\ItemData( $post_id, false ); | |
| 937 | + $format = $WelItem->get_opt_format(); | |
| 938 | + | |
| 939 | + $format['post_id'] = $post_id; | |
| 940 | + $format['code'] = $newoptcode; | |
| 941 | + $format['name'] = str_replace( "\\", '', $newoptname ); | |
| 942 | + $format['means'] = $newoptmeans; | |
| 943 | + $format['essential'] = $newoptessential; | |
| 944 | + $format['value'] = str_replace( "\\", '', $newoptvalue ); | |
| 945 | + | |
| 946 | + $value = $usces->stripslashes_deep_post( $format ); | |
| 947 | + | |
| 948 | + $id = usces_add_opt( $post_id, $value ); | |
| 949 | + | |
| 950 | + return $id; | |
| 951 | + } else { | |
| 952 | + return false; | |
| 953 | + } | |
| 954 | +} | |
| 955 | + | |
| 956 | +/** | |
| 957 | + * Update Item Option by ajax. | |
| 958 | + * Ajax response when Option information is updated in the Option block of the product registration screen. | |
| 959 | + * | |
| 960 | + * @since 2.3.3 | |
| 961 | + * @param string $post_ID Post ID. | |
| 962 | + * @return Query result. | |
| 963 | + */ | |
| 964 | +function up_item_option_meta( $post_ID ) { | |
| 965 | + global $usces; | |
| 966 | + | |
| 967 | + $post_id = (int) $post_ID; | |
| 968 | + $value = array(); | |
| 969 | + | |
| 970 | + $args = array( | |
| 971 | + 'optmetaid' => FILTER_VALIDATE_INT, | |
| 972 | + 'optcode' => FILTER_DEFAULT, | |
| 973 | + 'optname' => FILTER_DEFAULT, | |
| 974 | + 'optmeans' => FILTER_VALIDATE_INT, | |
| 975 | + 'optessential' => FILTER_VALIDATE_INT, | |
| 976 | + 'sort' => FILTER_VALIDATE_INT, | |
| 977 | + 'optvalue' => FILTER_DEFAULT, | |
| 978 | + ); | |
| 979 | + | |
| 980 | + $inputs = filter_input_array( INPUT_POST, $args ); | |
| 981 | + | |
| 982 | + $optmetaid = ( null !== $inputs['optmetaid'] ) ? (int) $inputs['optmetaid'] : ''; | |
| 983 | + $optcode = ( null !== $inputs['optcode'] ) ? $inputs['optcode'] : ''; | |
| 984 | + $optname = ( null !== $inputs['optname'] ) ? $inputs['optname'] : ''; | |
| 985 | + $optmeans = ( null !== $inputs['optmeans'] ) ? (int) $inputs['optmeans'] : 0; | |
| 986 | + $optessential = ( null !== $inputs['optessential'] ) ? $inputs['optessential'] : 0; | |
| 987 | + $optsort = ( null !== $inputs['sort'] ) ? $inputs['sort'] : 0; | |
| 988 | + $optvalue = ( null !== $inputs['optvalue'] ) ? trim( $inputs['optvalue'] ) : ''; | |
| 989 | + | |
| 990 | + $opts = wel_get_opts( $post_id, 'meta_id', false ); | |
| 991 | + $opt = $opts[ $optmetaid ]; | |
| 992 | + | |
| 993 | + $opt['meta_id'] = $optmetaid; | |
| 994 | + $opt['code'] = $optcode; | |
| 995 | + $opt['name'] = str_replace( "\\", '', $optname ); | |
| 996 | + $opt['means'] = $optmeans; | |
| 997 | + $opt['essential'] = $optessential; | |
| 998 | + $opt['value'] = str_replace( "\\", '', $optvalue ); | |
| 999 | + $opt['sort'] = $optsort; | |
| 1000 | + | |
| 1001 | + $value = $usces->stripslashes_deep_post( $opt ); | |
| 1002 | + | |
| 1003 | + $res = wel_update_opt_data_by_id( $optmetaid, $post_id, $value ); | |
| 1004 | + | |
| 1005 | + return $res; | |
| 1006 | +} | |
| 1007 | + | |
| 1008 | +/** | |
| 1009 | + * Delete item option meta | |
| 1010 | + * | |
| 1011 | + * @param int $post_id Post ID. | |
| 1012 | + */ | |
| 1013 | +function del_item_option_meta( $post_id ) { | |
| 1014 | + | |
| 1015 | + $optmetaid = filter_input( INPUT_POST, 'optmetaid', FILTER_VALIDATE_INT ); | |
| 1016 | + $meta_id = ( null !== $optmetaid ) ? $optmetaid : ''; | |
| 1017 | + | |
| 1018 | + wel_delete_opt_data_by_id( $meta_id, $post_id ); | |
| 1019 | + | |
| 1020 | + $opts = wel_get_opts( $post_id, 'sort', false ); | |
| 1021 | + if ( ! empty( $opts ) ) { | |
| 1022 | + $i = 0; | |
| 1023 | + foreach ( $opts as $opt ) { | |
| 1024 | + $opt['sort'] = $i; | |
| 1025 | + $meta_id = $opt['meta_id']; | |
| 1026 | + wel_update_opt_data_by_id( $meta_id, $post_id, $opt ); | |
| 1027 | + $i++; | |
| 1028 | + } | |
| 1029 | + } else { | |
| 1030 | + return; | |
| 1031 | + } | |
| 1032 | +} | |
| 1033 | + | |
| 1034 | +/** | |
| 1035 | + * Select common option | |
| 1036 | + * | |
| 1037 | + * @param int $post_id Post ID. | |
| 1038 | + * @return array | |
| 1039 | + */ | |
| 1040 | +function select_common_option( $post_id ) { | |
| 1041 | + | |
| 1042 | + $meta_id = filter_input( INPUT_POST, 'meta_id', FILTER_VALIDATE_INT ); | |
| 1043 | + if ( ! $meta_id ) { | |
| 1044 | + return array(); | |
| 1045 | + } | |
| 1046 | + | |
| 1047 | + $opts = wel_get_opts( $post_id, 'meta_id', false ); | |
| 1048 | + $opt = $opts[ $meta_id ]; | |
| 1049 | + $res = array( | |
| 1050 | + 'means' => $opt['means'], | |
| 1051 | + 'essential' => $opt['essential'], | |
| 1052 | + 'value' => $opt['value'], | |
| 1053 | + ); | |
| 1054 | + return $res; | |
| 1055 | +} | |
| 1056 | + | |
| 1057 | +/** | |
| 1058 | + * Order item2cart ajax | |
| 1059 | + */ | |
| 1060 | +function order_item2cart_ajax() { | |
| 1061 | + global $usces; | |
| 1062 | + | |
| 1063 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1064 | + | |
| 1065 | + if ( 'order_item2cart_ajax' !== $_POST['action'] ) { | |
| 1066 | + die(0); | |
| 1067 | + } | |
| 1068 | + | |
| 1069 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 1070 | + $logger = Logger::start( $_POST['order_id'], 'orderedit', 'update' ); | |
| 1071 | + $order_id = usces_add_ordercartdata(); | |
| 1072 | + if ( ! $order_id ) { | |
| 1073 | + die( 0 ); | |
| 1074 | + } | |
| 1075 | + | |
| 1076 | + $cart = usces_get_ordercartdata( $order_id ); | |
| 1077 | + $return = usces_get_ordercart_row( $order_id, $cart ); | |
| 1078 | + $logger->flush(); | |
| 1079 | + die( $return ); | |
| 1080 | +} | |
| 1081 | + | |
| 1082 | +/** | |
| 1083 | + * Order item ajax | |
| 1084 | + */ | |
| 1085 | +function order_item_ajax() { | |
| 1086 | + global $usces; | |
| 1087 | + | |
| 1088 | + if ( ! current_user_can( 'wel_manage_order' ) ) { | |
| 1089 | + wp_die( __( 'You do not have sufficient privileges to perform this operation.', 'usces' ) ); | |
| 1090 | + } | |
| 1091 | + | |
| 1092 | + if ( 'order_item_ajax' !== wp_unslash( $_POST['action'] ) ) { | |
| 1093 | + die(0); | |
| 1094 | + } | |
| 1095 | + | |
| 1096 | + $res = false; | |
| 1097 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 1098 | + $mode = sanitize_text_field( wp_unslash( $_POST['mode'] ) ); | |
| 1099 | + | |
| 1100 | + switch ( $mode ) { | |
| 1101 | + case 'completionMail': | |
| 1102 | + case 'orderConfirmMail': | |
| 1103 | + case 'changeConfirmMail': | |
| 1104 | + case 'receiptConfirmMail': | |
| 1105 | + case 'mitumoriConfirmMail': | |
| 1106 | + case 'cancelConfirmMail': | |
| 1107 | + case 'otherConfirmMail': | |
| 1108 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1109 | + $order_id = (int) wp_unslash( $_POST['order_id'] ); | |
| 1110 | + $res = usces_order_confirm_message( $order_id ); | |
| 1111 | + break; | |
| 1112 | + case 'sendmail': | |
| 1113 | + // Nonce('wc_send_mail_order_nonce') verification is executed in the usces_ajax_send_mail function. | |
| 1114 | + $res = usces_ajax_send_mail(); | |
| 1115 | + break; | |
| 1116 | + case 'get_order_item': | |
| 1117 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1118 | + $itemcode = sanitize_text_field( wp_unslash( $_POST['itemcode'] ) ); | |
| 1119 | + $res = get_order_item( $itemcode ); | |
| 1120 | + break; | |
| 1121 | + case 'get_item_select_option': | |
| 1122 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1123 | + $cat_id = (int) wp_unslash( $_POST['cat_id'] ); | |
| 1124 | + $res = usces_get_item_select_option( $cat_id ); | |
| 1125 | + break; | |
| 1126 | + case 'ordercheckpost': | |
| 1127 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1128 | + $res = usces_update_ordercheck(); | |
| 1129 | + break; | |
| 1130 | + case 'getmember': | |
| 1131 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1132 | + $res = usces_get_member_neworder(); | |
| 1133 | + break; | |
| 1134 | + case 'recalculation': | |
| 1135 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1136 | + $change_taxrate = ( isset( $_POST['change_taxrate'] ) ) ? sanitize_text_field( wp_unslash( $_POST['change_taxrate'] ) ) : ''; | |
| 1137 | + $order_id = (int) wp_unslash( $_POST['order_id'] ); | |
| 1138 | + $mem_id = (int) wp_unslash( $_POST['mem_id'] ); | |
| 1139 | + $res = usces_order_recalculation( $order_id, $mem_id, $_POST['post_ids'], $_POST['prices'], $_POST['quants'], $_POST['cart_ids'], $_POST['upoint'], $_POST['shipping_charge'], $_POST['cod_fee'], $_POST['discount'], $change_taxrate ); | |
| 1140 | + break; | |
| 1141 | + case 'recalculation_reduced': | |
| 1142 | + check_ajax_referer( 'order_edit', 'wc_nonce' ); | |
| 1143 | + $change_taxrate = ( isset( $_POST['change_taxrate'] ) ) ? sanitize_text_field( wp_unslash( $_POST['change_taxrate'] ) ) : ''; | |
| 1144 | + $order_id = (int) wp_unslash( $_POST['order_id'] ); | |
| 1145 | + $mem_id = (int) wp_unslash( $_POST['mem_id'] ); | |
| 1146 | + $res = usces_order_recalculation_reduced( $order_id, $mem_id, $_POST['post_ids'], $_POST['prices'], $_POST['quants'], $_POST['cart_ids'], $_POST['upoint'], $_POST['shipping_charge'], $_POST['cod_fee'], $_POST['discount_standard'], $_POST['discount_reduced'], $change_taxrate ); | |
| 1147 | + break; | |
| 1148 | + case 'get_settlement_log': | |
| 1149 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1150 | + $res = usces_get_settlement_log(); | |
| 1151 | + break; | |
| 1152 | + case 'get_settlement_log_detail': | |
| 1153 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1154 | + $log_key = sanitize_text_field( wp_unslash( $_POST['log_key'] ) ); | |
| 1155 | + $res = usces_get_settlement_log_detail( $log_key ); | |
| 1156 | + break; | |
| 1157 | + case 'search_settlement_log': | |
| 1158 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1159 | + $log_key = sanitize_text_field( wp_unslash( $_POST['log_key'] ) ); | |
| 1160 | + $res = usces_get_settlement_log( $log_key ); | |
| 1161 | + break; | |
| 1162 | + case 'delete_settlement_log': | |
| 1163 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1164 | + $log_key = sanitize_text_field( wp_unslash( $_POST['log_key'] ) ); | |
| 1165 | + usces_delete_settlement_log( $log_key ); | |
| 1166 | + $res = usces_get_settlement_log(); | |
| 1167 | + break; | |
| 1168 | + case 'delete_settlement_log_all': | |
| 1169 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1170 | + usces_delete_settlement_log(); | |
| 1171 | + $res = usces_get_settlement_log(); | |
| 1172 | + break; | |
| 1173 | + case 'revival_order_data': | |
| 1174 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1175 | + $log_key = sanitize_text_field( wp_unslash( $_POST['log_key'] ) ); | |
| 1176 | + $register_date = sanitize_text_field( wp_unslash( $_POST['register_date'] ) ); | |
| 1177 | + $res = usces_revival_order_data( $log_key, $register_date ); | |
| 1178 | + break; | |
| 1179 | + case 'get_settlement_error_log': | |
| 1180 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1181 | + $res = usces_get_settlement_error_log(); | |
| 1182 | + break; | |
| 1183 | + case 'get_settlement_error_log_detail': | |
| 1184 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1185 | + $log_id = sanitize_text_field( wp_unslash( $_POST['log_id'] ) ); | |
| 1186 | + $res = usces_get_settlement_error_log_detail( $log_id ); | |
| 1187 | + break; | |
| 1188 | + case 'delete_settlement_error_log': | |
| 1189 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1190 | + $log_id = sanitize_text_field( wp_unslash( $_POST['log_id'] ) ); | |
| 1191 | + usces_delete_settlement_error_log( $log_id ); | |
| 1192 | + $res = usces_get_settlement_error_log(); | |
| 1193 | + break; | |
| 1194 | + case 'delete_settlement_error_log_all': | |
| 1195 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1196 | + usces_delete_settlement_error_log(); | |
| 1197 | + $res = usces_get_settlement_error_log(); | |
| 1198 | + break; | |
| 1199 | + case 'reset_settlement_notice': | |
| 1200 | + check_ajax_referer( 'order_list', 'wc_nonce' ); | |
| 1201 | + $res = usces_reset_settlement_notice(); | |
| 1202 | + break; | |
| 1203 | + } | |
| 1204 | + | |
| 1205 | + $res = wel_esc_script( apply_filters( 'usces_filter_order_item_ajax', $res ) ); | |
| 1206 | + | |
| 1207 | + if ( false === $res ) { | |
| 1208 | + die(0); | |
| 1209 | + } | |
| 1210 | + | |
| 1211 | + die( $res ); | |
| 1212 | +} | |
| 1213 | + | |
| 1214 | +/** | |
| 1215 | + * Item select field | |
| 1216 | + * | |
| 1217 | + * @param int $cat_id Category ID. | |
| 1218 | + * @return string | |
| 1219 | + */ | |
| 1220 | +function usces_get_item_select_option( $cat_id ) { | |
| 1221 | + global $usces; | |
| 1222 | + | |
| 1223 | + $number = apply_filters( 'usces_filter_item_select_numberposts', 50, $cat_id ); | |
| 1224 | + $args = array( | |
| 1225 | + 'category' => $cat_id, | |
| 1226 | + 'numberposts' => $number, | |
| 1227 | + 'post_status' => array( 'publish', 'private' ), | |
| 1228 | + ); | |
| 1229 | + $args = apply_filters( 'usces_filter_item_select_queryargs', $args, $cat_id ); | |
| 1230 | + | |
| 1231 | + $items = get_posts( $args ); | |
| 1232 | + $option = '<option value="-1">' . __( 'Please select an item', 'usces' ) . '</option>' . "\n"; | |
| 1233 | + foreach ( (array) $items as $item ) { | |
| 1234 | + $product = wel_get_product( $item->ID ); | |
| 1235 | + $item_name = $product['itemName']; | |
| 1236 | + $item_code = $product['itemCode']; | |
| 1237 | + $option .= '<option value="' . urlencode( $item_code ) . '">' . esc_html( $item_name ) . '(' . esc_html( $item_code ) . ')</option>' . "\n"; | |
| 1238 | + } | |
| 1239 | + return $option; | |
| 1240 | +} | |
| 1241 | + | |
| 1242 | +/** | |
| 1243 | + * Order Item html | |
| 1244 | + */ | |
| 1245 | +function usces_get_member_neworder() { | |
| 1246 | + global $wpdb; | |
| 1247 | + | |
| 1248 | + $wpdb->show_errors(); | |
| 1249 | + $res = ''; | |
| 1250 | + $member_table = usces_get_tablename( 'usces_member' ); | |
| 1251 | + $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s", trim( $_POST['email'] ) ); | |
| 1252 | + $value = $wpdb->get_row( $query, ARRAY_A ); | |
| 1253 | + | |
| 1254 | + if ( ! $value ) { | |
| 1255 | + $response = array( 'status_code' => 'none' ); | |
| 1256 | + wp_send_json( $response ); | |
| 1257 | + } | |
| 1258 | + | |
| 1259 | + $response = array( | |
| 1260 | + 'status_code' => 'ok', | |
| 1261 | + 'member_id' => $value['ID'], | |
| 1262 | + 'customer[name1]' => $value['mem_name1'], | |
| 1263 | + 'customer[name2]' => $value['mem_name2'], | |
| 1264 | + 'customer[name3]' => $value['mem_name3'], | |
| 1265 | + 'customer[name4]' => $value['mem_name4'], | |
| 1266 | + 'customer[zipcode]' => $value['mem_zip'], | |
| 1267 | + 'customer[pref]' => $value['mem_pref'], | |
| 1268 | + 'customer[address1]' => $value['mem_address1'], | |
| 1269 | + 'customer[address2]' => $value['mem_address2'], | |
| 1270 | + 'customer[address3]' => $value['mem_address3'], | |
| 1271 | + 'customer[tel]' => $value['mem_tel'], | |
| 1272 | + 'customer[fax]' => $value['mem_fax'], | |
| 1273 | + 'delivery[name1]' => $value['mem_name1'], | |
| 1274 | + 'delivery[name2]' => $value['mem_name2'], | |
| 1275 | + 'delivery[name3]' => $value['mem_name3'], | |
| 1276 | + 'delivery[name4]' => $value['mem_name4'], | |
| 1277 | + 'delivery[zipcode]' => $value['mem_zip'], | |
| 1278 | + 'delivery[pref]' => $value['mem_pref'], | |
| 1279 | + 'delivery[address1]' => $value['mem_address1'], | |
| 1280 | + 'delivery[address2]' => $value['mem_address2'], | |
| 1281 | + 'delivery[address3]' => $value['mem_address3'], | |
| 1282 | + 'delivery[tel]' => $value['mem_tel'], | |
| 1283 | + 'delivery[fax]' => $value['mem_fax'], | |
| 1284 | + ); | |
| 1285 | + | |
| 1286 | + $member_metetable = usces_get_tablename( 'usces_member_meta' ); | |
| 1287 | + $query = $wpdb->prepare( "SELECT * FROM $member_metetable WHERE meta_key LIKE %s AND member_id = %d", 'csmb_%', $value['ID'] ); | |
| 1288 | + $customs = $wpdb->get_results( $query, ARRAY_A ); | |
| 1289 | + if ( ! empty( $customs ) ) { | |
| 1290 | + foreach ( $customs as $cusv ) { | |
| 1291 | + $response[ 'custom_customer[' . substr( $cusv['meta_key'], 5 ) . ']'] = $cusv['meta_value']; | |
| 1292 | + $response[ 'custom_delivery[' . substr( $cusv['meta_key'], 5 ) . ']'] = $cusv['meta_value']; | |
| 1293 | + } | |
| 1294 | + } | |
| 1295 | + | |
| 1296 | + $response = apply_filters( 'usces_filter_get_member_neworder', $response ); | |
| 1297 | + | |
| 1298 | + wp_send_json( $response ); | |
| 1299 | +} | |
| 1300 | + | |
| 1301 | +/** | |
| 1302 | + * Add to order cart | |
| 1303 | + * | |
| 1304 | + * @return mixed | |
| 1305 | + */ | |
| 1306 | +function usces_add_ordercartdata() { | |
| 1307 | + global $usces, $wpdb; | |
| 1308 | + | |
| 1309 | + $res = 0; | |
| 1310 | + | |
| 1311 | + $order_id = (int) $_POST['order_id']; | |
| 1312 | + if ( ! $order_id ) { | |
| 1313 | + return $res; | |
| 1314 | + } | |
| 1315 | + | |
| 1316 | + $post_id = (int) $_POST['post_id']; | |
| 1317 | + $sku_code = urldecode( $_POST['sku'] ); | |
| 1318 | + $quantity = 1; | |
| 1319 | + | |
| 1320 | + $current_cart = usces_get_ordercartdata( $order_id ); | |
| 1321 | + $temp_arr = array(); | |
| 1322 | + foreach ( $current_cart as $cv ) { | |
| 1323 | + $temp_arr[] = $cv['row_index']; | |
| 1324 | + } | |
| 1325 | + $row_index = ( 0 < count( $temp_arr ) ) ? max( $temp_arr ) + 1 : 0; | |
| 1326 | + | |
| 1327 | + $cart_table = $wpdb->prefix . 'usces_ordercart'; | |
| 1328 | + $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta'; | |
| 1329 | + | |
| 1330 | + $product = wel_get_product( $post_id ); | |
| 1331 | + $item_name = $product['itemName']; | |
| 1332 | + $item_code = $product['itemCode']; | |
| 1333 | + $skus = $usces->get_skus( $post_id, 'code' ); | |
| 1334 | + $sku = apply_filters( 'usces_filter_add_ordercart_sku', $skus[ $sku_code ], $_POST ); | |
| 1335 | + $tax = 0; | |
| 1336 | + | |
| 1337 | + $query = $wpdb->prepare( | |
| 1338 | + "INSERT INTO $cart_table | |
| 1339 | + ( | |
| 1340 | + order_id, row_index, post_id, item_code, item_name, | |
| 1341 | + sku_code, sku_name, cprice, price, quantity, | |
| 1342 | + unit, tax, destination_id, cart_serial | |
| 1343 | + ) VALUES ( | |
| 1344 | + %d, %d, %d, %s, %s, | |
| 1345 | + %s, %s, %f, %f, %d, | |
| 1346 | + %s, %d, %d, %s | |
| 1347 | + )", | |
| 1348 | + $order_id, $row_index, $post_id, $item_code, $item_name, | |
| 1349 | + $sku_code, $sku['name'], $sku['cprice'], $sku['price'], $quantity, | |
| 1350 | + $sku['unit'], $tax, NULL, NULL | |
| 1351 | + ); | |
| 1352 | + $res = $wpdb->query( $query ); | |
| 1353 | + $cart_id = NULL; | |
| 1354 | + if ( false !== $res ) { | |
| 1355 | + $cart_id = $wpdb->insert_id; | |
| 1356 | + | |
| 1357 | + $item_opts = usces_get_opts( $post_id, 'name' ); | |
| 1358 | + foreach ( $item_opts as $key => $iopts ) { | |
| 1359 | + if ( 3 === (int) $iopts['means'] || 4 === (int) $iopts['means'] ) { | |
| 1360 | + // POSTが無ければNULLで追加. | |
| 1361 | + if ( ! isset( $_POST['itemOption'][ $key ] ) ) { | |
| 1362 | + $query = $wpdb->prepare( | |
| 1363 | + "INSERT INTO $cart_meta_table | |
| 1364 | + ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )", | |
| 1365 | + $cart_id, 'option', $iopts['name'], NULL | |
| 1366 | + ); | |
| 1367 | + $wpdb->query( $query ); | |
| 1368 | + } | |
| 1369 | + } | |
| 1370 | + } | |
| 1371 | + | |
| 1372 | + if ( isset( $_POST['itemOption'] ) ) { | |
| 1373 | + foreach ( (array) $_POST['itemOption'] as $okey => $ovalue ) { | |
| 1374 | + $means = $item_opts[ $okey ]['means']; | |
| 1375 | + if ( is_array( $ovalue ) ) { | |
| 1376 | + $temp = array(); | |
| 1377 | + if ( 4 === (int) $means ) { | |
| 1378 | + foreach ( $ovalue as $k => $v ) { | |
| 1379 | + $temp[] = $v; | |
| 1380 | + } | |
| 1381 | + } else { | |
| 1382 | + foreach ( $ovalue as $k => $v ) { | |
| 1383 | + $temp[ urlencode( $k ) ] = $v; | |
| 1384 | + } | |
| 1385 | + } | |
| 1386 | + $ovalue = serialize( $temp ); | |
| 1387 | + } else { | |
| 1388 | + $ovalue = $ovalue; | |
| 1389 | + } | |
| 1390 | + $aquery = $wpdb->prepare( | |
| 1391 | + "INSERT INTO $cart_meta_table | |
| 1392 | + ( cart_id, meta_type, meta_key, meta_value ) VALUES (%d, %s, %s, %s)", | |
| 1393 | + $cart_id, 'option', $okey, $ovalue | |
| 1394 | + ); | |
| 1395 | + $wpdb->query( $aquery ); | |
| 1396 | + } | |
| 1397 | + } | |
| 1398 | + | |
| 1399 | + if ( $usces->is_reduced_taxrate() ) { | |
| 1400 | + if ( isset( $sku['taxrate'] ) && 'reduced' === $sku['taxrate'] ) { | |
| 1401 | + $tkey = 'reduced'; | |
| 1402 | + $tvalue = $usces->options['tax_rate_reduced']; | |
| 1403 | + } else { | |
| 1404 | + $tkey = 'standard'; | |
| 1405 | + $tvalue = $usces->options['tax_rate']; | |
| 1406 | + } | |
| 1407 | + $tquery = $wpdb->prepare( | |
| 1408 | + "INSERT INTO $cart_meta_table | |
| 1409 | + ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, 'taxrate', %s, %s )", | |
| 1410 | + $cart_id, $tkey, $tvalue | |
| 1411 | + ); | |
| 1412 | + $wpdb->query( $tquery ); | |
| 1413 | + } | |
| 1414 | + } | |
| 1415 | + | |
| 1416 | + $res = apply_filters( 'usces_filter_add_ordercart', $res, $order_id, $cart_id ); | |
| 1417 | + | |
| 1418 | + if ( $res ) { | |
| 1419 | + return $order_id; | |
| 1420 | + } else { | |
| 1421 | + return $res; | |
| 1422 | + } | |
| 1423 | +} | |
| 1424 | + | |
| 1425 | +/** | |
| 1426 | + * Get order item | |
| 1427 | + * | |
| 1428 | + * @param string $item_code Item code. | |
| 1429 | + * @return string | |
| 1430 | + */ | |
| 1431 | +function get_order_item( $item_code ) { | |
| 1432 | + global $usces, $post; | |
| 1433 | + | |
| 1434 | + $post_id = wel_get_id_by_item_code( $item_code ); | |
| 1435 | + if ( null === $post_id ) { | |
| 1436 | + return false; | |
| 1437 | + } | |
| 1438 | + $product = wel_get_product( $post_id ); | |
| 1439 | + if ( null === $product ) { | |
| 1440 | + return false; | |
| 1441 | + } | |
| 1442 | + $post = $product['_pst']; | |
| 1443 | + $res = apply_filters( 'usce_action_ajax_get_order_item', false, $post ); | |
| 1444 | + if ( false !== $res ) { | |
| 1445 | + return $res; | |
| 1446 | + } | |
| 1447 | + | |
| 1448 | + $pict_id = wel_get_main_pict_id_by_code( $item_code ); | |
| 1449 | + $pict_link = wp_get_attachment_image( $pict_id, array( 150, 150 ), true ); | |
| 1450 | + preg_match( "/^\<a .+\>(\<img .+\/\>)\<\/a\>$/", $pict_link, $match ); | |
| 1451 | + $pict = isset( $match[1] ) ? $match[1] : ''; | |
| 1452 | + $skus = $product['_sku']; | |
| 1453 | + $optkeys = $usces->get_itemOptionKey( $post_id ); | |
| 1454 | + $item_name = esc_html( $product['itemName'] ); | |
| 1455 | + | |
| 1456 | + $r = ''; | |
| 1457 | + $r .= $pict_link . "\n"; | |
| 1458 | + $r .= '<h3>' . $item_name . "</h3>\n"; | |
| 1459 | + $r .= "<div class=\"skuform\">\n"; | |
| 1460 | + | |
| 1461 | + $r .= "<table class=\"skumulti\">\n"; | |
| 1462 | + $r .= "<thead>\n"; | |
| 1463 | + $r .= "<tr>\n"; | |
| 1464 | + $r .= '<th>' . __( 'SKU code', 'usces' ) . "</th>\n"; | |
| 1465 | + $r .= '<th>' . __( 'SKU display name ', 'usces' ) . "</th>\n"; | |
| 1466 | + | |
| 1467 | + $usces_listprice = __( 'List price', 'usces' ) . usces_guid_tax( 'return' ); | |
| 1468 | + $r .= '<th>' . apply_filters( 'usces_filter_listprice_label', $usces_listprice, __( 'List price', 'usces' ), usces_guid_tax( 'return' ) ) . "</th>\n"; | |
| 1469 | + | |
| 1470 | + $usces_sellingprice = __( 'Sale price', 'usces' ) . usces_guid_tax( 'return' ); | |
| 1471 | + $r .= '<th>' . apply_filters( 'usces_filter_sellingprice_label', $usces_sellingprice, __( 'Sale price', 'usces' ), usces_guid_tax( 'return' ) ) . "</th>\n"; | |
| 1472 | + | |
| 1473 | + $r .= '<th>' . __( 'stock status', 'usces' ) . "</th>\n"; | |
| 1474 | + $r .= '<th>' . __( 'stock', 'usces' ) . "</th>\n"; | |
| 1475 | + $r .= '<th>' . __( 'unit', 'usces' ) . "</th>\n"; | |
| 1476 | + $r .= "<th> </th>\n"; | |
| 1477 | + $r .= "</tr>\n"; | |
| 1478 | + $r .= "</thead>\n"; | |
| 1479 | + $r .= "<tbody>\n"; | |
| 1480 | + foreach ( $skus as $sku ) : | |
| 1481 | + $key = urlencode( $sku['code'] ); | |
| 1482 | + $cprice = esc_attr( $sku['cprice'] ); | |
| 1483 | + $price = esc_attr( $sku['price'] ); | |
| 1484 | + $zaiko = esc_attr( $usces->zaiko_status[ $sku['stock'] ] ); | |
| 1485 | + $zaikonum = esc_attr( $sku['stocknum'] ); | |
| 1486 | + $disp = esc_attr( $sku['name'] ); | |
| 1487 | + $unit = esc_attr( $sku['unit'] ); | |
| 1488 | + $gptekiyo = $sku['gp']; | |
| 1489 | + $sort = (int) $sku['sort']; | |
| 1490 | + | |
| 1491 | + $r .= "<tr>\n"; | |
| 1492 | + $r .= '<td rowspan="2">' . esc_js( $sku['code'] ) . "</td>\n"; | |
| 1493 | + $r .= '<td>' . $disp . "</td>\n"; | |
| 1494 | + $r .= '<td><span class="cprice">' . ( ( ! empty( $cprice ) ) ? usces_crform( $cprice, true, false, 'return' ) : '' ) . "</span></td>\n"; | |
| 1495 | + $r .= '<td><span class="price">' . usces_crform( $price, true, false, 'return' ) . "</span></td>\n"; | |
| 1496 | + $r .= '<td>' . $zaiko . "</td>\n"; | |
| 1497 | + $r .= '<td>' . $zaikonum . "</td>\n"; | |
| 1498 | + $r .= '<td>' . $unit . "</td>\n"; | |
| 1499 | + $r .= "<td>\n"; | |
| 1500 | + $r .= "<input name=\"itemNEWName[{$post_id}][{$key}]\" type=\"hidden\" id=\"itemNEWName[{$post_id}][{$key}]\" value=\"{$item_name}\" />\n"; | |
| 1501 | + $r .= "<input name=\"itemNEWCode[{$post_id}][{$key}]\" type=\"hidden\" id=\"itemNEWCode[{$post_id}][{$key}]\" value=\"{$item_code}\" />\n"; | |
| 1502 | + $r .= "<input name=\"skuNEWName[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWName[{$post_id}][{$key}]\" value=\"{$key}\" />\n"; | |
| 1503 | + $r .= "<input name=\"skuNEWCprice[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWCprice[{$post_id}][{$key}]\" value=\"{$cprice}\" />\n"; | |
| 1504 | + $r .= "<input name=\"skuNEWDisp[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWDisp[{$post_id}][{$key}]\" value=\"{$disp}\" />\n"; | |
| 1505 | + $r .= "<input name=\"zaikoNEWnum[{$post_id}][{$key}]\" type=\"hidden\" id=\"zaikoNEWnum[{$post_id}][{$key}]\" value=\"{$zaikonum}\" />\n"; | |
| 1506 | + $r .= "<input name=\"zaiNEWko[{$post_id}][{$key}]\" type=\"hidden\" id=\"zaiNEWko[{$post_id}][{$key}]\" value=\"{$zaiko}\" />\n"; | |
| 1507 | + $r .= "<input name=\"uniNEWt[{$post_id}][{$key}]\" type=\"hidden\" id=\"uniNEWt[{$post_id}][{$key}]\" value=\"{$unit}\" />\n"; | |
| 1508 | + $r .= "<input name=\"gpNEWtekiyo[{$post_id}][{$key}]\" type=\"hidden\" id=\"gpNEWtekiyo[{$post_id}][{$key}]\" value=\"{$gptekiyo}\" />\n"; | |
| 1509 | + $r .= "<input name=\"skuNEWPrice[{$post_id}][{$key}]\" type=\"hidden\" id=\"skuNEWPrice[{$post_id}][{$key}]\" value=\"{$price}\" />\n"; | |
| 1510 | + $r .= "<input name=\"inNEWCart[{$post_id}][{$key}]\" type=\"button\" id=\"inNEWCart[{$post_id}][{$key}]\" class=\"skubutton button\" value=\"" . __( 'Add to Whish List', 'usces' ) . "\" onclick=\"orderItem.add2cart('{$post_id}', '{$key}');\" />"; | |
| 1511 | + $r .= "</td>\n"; | |
| 1512 | + $r .= "</tr>\n"; | |
| 1513 | + $r .= "<tr>\n"; | |
| 1514 | + if ( $optkeys ) : | |
| 1515 | + $r .= "<td colspan=\"7\">\n"; | |
| 1516 | + foreach ( $optkeys as $optkey => $optvalue ) : | |
| 1517 | + $r .= "<div>\n"; | |
| 1518 | + | |
| 1519 | + $name = esc_attr( $optvalue ); | |
| 1520 | + $optcode = urlencode( $name ); | |
| 1521 | + $opts = usces_get_opts( $post_id, 'name' ); | |
| 1522 | + $opt = $opts[ $optvalue ]; | |
| 1523 | + $opt['value'] = usces_change_line_break( $opt['value'] ); | |
| 1524 | + $means = (int) $opt['means']; | |
| 1525 | + $essential = (int) $opt['essential']; | |
| 1526 | + | |
| 1527 | + $r .= "\n<label for=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" class=\"iopt_label\">{$name}</label>\n"; | |
| 1528 | + switch ( $means ) { | |
| 1529 | + case 0: // Single-select. | |
| 1530 | + case 1: // Multi-select. | |
| 1531 | + $selects = explode( "\n", $opt['value'] ); | |
| 1532 | + $multiple = ( 0 === $means ) ? '' : ' multiple'; | |
| 1533 | + $multiple_array = ( 0 === $means ) ? '' : '_multiple'; | |
| 1534 | + $r .= "\n<select name=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" id=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" class=\"iopt_select{$multiple_array}\"{$multiple}>\n"; | |
| 1535 | + if ( 1 === $essential ) { | |
| 1536 | + $r .= "\t<option value=\"#NONE#\" selected=\"selected\">" . __( 'Choose', 'usces' ) . "</option>\n"; | |
| 1537 | + } | |
| 1538 | + $s = 0; | |
| 1539 | + foreach ( $selects as $v ) { | |
| 1540 | + $v = trim( $v ); | |
| 1541 | + if ( 0 === $s && 0 === $essential ) { | |
| 1542 | + $selected = ' selected="selected"'; | |
| 1543 | + } else { | |
| 1544 | + $selected = ''; | |
| 1545 | + } | |
| 1546 | + $r .= "\t<option value=\"{$v}\"{$selected}>{$v}</option>\n"; | |
| 1547 | + $s++; | |
| 1548 | + } | |
| 1549 | + $r .= "</select>\n"; | |
| 1550 | + break; | |
| 1551 | + case 2: // Text. | |
| 1552 | + $r .= "\n<input name=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" type=\"text\" id=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" class=\"iopt_text\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"\" />\n"; | |
| 1553 | + break; | |
| 1554 | + case 3: // Radio-button. | |
| 1555 | + $selects = explode( "\n", $opt['value'] ); | |
| 1556 | + $i = 0; | |
| 1557 | + foreach ( $selects as $v ) { | |
| 1558 | + $r .= '<label for="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_radio_label"><input name="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']" type="radio" id="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_radio" value="' . urlencode($v) . '">' . esc_html($v) . "</label>\n"; | |
| 1559 | + $i++; | |
| 1560 | + } | |
| 1561 | + break; | |
| 1562 | + case 4: // Check-box. | |
| 1563 | + $selects = explode( "\n", $opt['value'] ); | |
| 1564 | + $i = 0; | |
| 1565 | + foreach ( $selects as $v ) { | |
| 1566 | + $r .= '<label for="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_checkbox_label"><input name="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']" type="checkbox" id="itemNEWOption[' . $post_id . '][' . $key . '][' . $optcode . ']' . $i . '" class="iopt_checkbox" value="' . urlencode($v) . '">' . esc_html($v) . "</label>\n"; | |
| 1567 | + $i++; | |
| 1568 | + } | |
| 1569 | + break; | |
| 1570 | + case 5: // Text-area. | |
| 1571 | + $r .= "\n<textarea name=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" id=\"itemNEWOption[{$post_id}][{$key}][{$optcode}]\" class=\"iopt_textarea\"></textarea>\n"; | |
| 1572 | + break; | |
| 1573 | + } | |
| 1574 | + $r .= "<input name=\"optNEWCode[{$post_id}][{$key}][{$optcode}]\" type=\"hidden\" id=\"optNEWCode[{$post_id}][{$key}][{$optcode}]\" value=\"{$optcode}\" />\n"; | |
| 1575 | + $r .= "<input name=\"optNEWEssential[{$post_id}][{$key}][{$optcode}]\" type=\"hidden\" id=\"optNEWEssential[{$post_id}][{$key}][{$optcode}]\" value=\"{$essential}\" />\n"; | |
| 1576 | + $r .= "</div>\n"; | |
| 1577 | + endforeach; | |
| 1578 | + $r .= "</td>\n"; | |
| 1579 | + endif; | |
| 1580 | + $r .= "</tr>\n"; | |
| 1581 | + endforeach; | |
| 1582 | + $r .= "</tbody>\n"; | |
| 1583 | + $r .= "</table>\n"; | |
| 1584 | + | |
| 1585 | + $r .= "</div>\n"; | |
| 1586 | + | |
| 1587 | + $r = apply_filters( 'usces_filter_get_order_item', $r, $item_code, $post_id ); | |
| 1588 | + | |
| 1589 | + return $r; | |
| 1590 | +} | |
| 1591 | + | |
| 1592 | +/** | |
| 1593 | + * Item option ajax | |
| 1594 | + */ | |
| 1595 | +function item_option_ajax() { | |
| 1596 | + | |
| 1597 | + $args = array( | |
| 1598 | + 'ID' => FILTER_VALIDATE_INT, | |
| 1599 | + 'action' => FILTER_DEFAULT, | |
| 1600 | + 'update' => FILTER_DEFAULT, | |
| 1601 | + 'delete' => FILTER_DEFAULT, | |
| 1602 | + 'meta' => FILTER_DEFAULT, | |
| 1603 | + 'select' => FILTER_DEFAULT, | |
| 1604 | + 'sort' => FILTER_VALIDATE_INT, | |
| 1605 | + ); | |
| 1606 | + | |
| 1607 | + $inputs = filter_input_array( INPUT_POST, $args ); | |
| 1608 | + | |
| 1609 | + check_admin_referer( 'admin_setup', 'wc_nonce' ); | |
| 1610 | + if ( ! current_user_can( 'edit_posts' ) ) { | |
| 1611 | + wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); | |
| 1612 | + } | |
| 1613 | + | |
| 1614 | + if ( 'item_option_ajax' !== $inputs['action'] || null === $inputs['ID'] ) { | |
| 1615 | + die(0); | |
| 1616 | + } | |
| 1617 | + | |
| 1618 | + $post_id = $inputs['ID']; | |
| 1619 | + | |
| 1620 | + if ( null !== $inputs['update'] ) { | |
| 1621 | + | |
| 1622 | + $id = up_item_option_meta( $post_id ); | |
| 1623 | + | |
| 1624 | + } elseif ( null !== $inputs['delete'] ) { | |
| 1625 | + | |
| 1626 | + $id = del_item_option_meta( $post_id ); | |
| 1627 | + | |
| 1628 | + } elseif ( null !== $inputs['select'] ) { | |
| 1629 | + | |
| 1630 | + $res = select_common_option( $post_id ); | |
| 1631 | + wp_send_json( $res ); | |
| 1632 | + | |
| 1633 | + } elseif ( null !== $inputs['sort'] ) { | |
| 1634 | + | |
| 1635 | + $id = usces_sort_item_opts( $post_id, $inputs['meta'] ); | |
| 1636 | + | |
| 1637 | + } else { | |
| 1638 | + | |
| 1639 | + $id = add_item_option_meta( $post_id ); | |
| 1640 | + | |
| 1641 | + } | |
| 1642 | + | |
| 1643 | + $opts = usces_get_opts( $post_id, 'sort', false ); | |
| 1644 | + | |
| 1645 | + $r = ''; | |
| 1646 | + foreach ( $opts as $opt ) { | |
| 1647 | + $r .= _list_item_option_meta_row( $opt ); | |
| 1648 | + } | |
| 1649 | + | |
| 1650 | + $response = array( | |
| 1651 | + 'meta_id' => $id, | |
| 1652 | + 'meta_row' => $r, | |
| 1653 | + ); | |
| 1654 | + wp_send_json( $response ); | |
| 1655 | +} | |
| 1656 | + | |
| 1657 | +/** | |
| 1658 | + * Item SKU ajax | |
| 1659 | + */ | |
| 1660 | +function item_sku_ajax() { | |
| 1661 | + global $usces; | |
| 1662 | + | |
| 1663 | + $id = ''; | |
| 1664 | + if ( 'item_sku_ajax' !== $_POST['action'] ) { | |
| 1665 | + die(0); | |
| 1666 | + } | |
| 1667 | + | |
| 1668 | + $post_id = (int) $_POST['ID']; | |
| 1669 | + $msg = ''; | |
| 1670 | + | |
| 1671 | + if ( ! current_user_can( 'wel_publish_products', $post_id ) ) { | |
| 1672 | + $response = array( | |
| 1673 | + 'meta_id' => 0, | |
| 1674 | + 'meta_row' => 0, | |
| 1675 | + 'meta_msg' => __( 'You are not allowed to edit this item.', 'usces' ), | |
| 1676 | + ); | |
| 1677 | + wp_send_json( $response ); | |
| 1678 | + } | |
| 1679 | + | |
| 1680 | + if ( isset( $_POST['update'] ) ) { | |
| 1681 | + check_ajax_referer( 'admin_setup', 'wc_nonce' ); | |
| 1682 | + $id = up_item_sku_meta( $post_id ); | |
| 1683 | + | |
| 1684 | + } elseif ( isset( $_POST['delete'] ) ) { | |
| 1685 | + check_ajax_referer( 'admin_setup', 'wc_nonce' ); | |
| 1686 | + $id = del_item_sku_meta( $post_id ); | |
| 1687 | + | |
| 1688 | + } elseif ( isset( $_POST['select'] ) ) { | |
| 1689 | + check_ajax_referer( 'admin_setup', 'wc_nonce' ); | |
| 1690 | + $response = select_item_sku( $post_id ); | |
| 1691 | + wp_send_json( $response ); | |
| 1692 | + | |
| 1693 | + } elseif ( isset( $_POST['sort'] ) ) { | |
| 1694 | + check_ajax_referer( 'admin_setup', 'wc_nonce' ); | |
| 1695 | + $id = usces_sort_item_skus( $post_id, $_POST['meta'] ); | |
| 1696 | + | |
| 1697 | + } else { | |
| 1698 | + check_ajax_referer( 'admin_setup', 'wc_nonce' ); | |
| 1699 | + $id = add_item_sku_meta( $post_id ); | |
| 1700 | + | |
| 1701 | + } | |
| 1702 | + $msg .= apply_filters( 'usces_filter_item_sku_message', $msg, $id, $post_id ); | |
| 1703 | + // $skus = $usces->get_skus( $post_id ); | |
| 1704 | + $skus = wel_get_skus( $post_id, 'sort', false ); | |
| 1705 | + | |
| 1706 | + $r = ''; | |
| 1707 | + | |
| 1708 | + foreach ( (array) $skus as $sku ) { | |
| 1709 | + $r .= _list_item_sku_meta_row( $sku ); | |
| 1710 | + } | |
| 1711 | + $response = array( | |
| 1712 | + 'meta_id' => $id, | |
| 1713 | + 'meta_row' => $r, | |
| 1714 | + 'meta_msg' => $msg, | |
| 1715 | + ); | |
| 1716 | + | |
| 1717 | + wp_send_json( $response ); | |
| 1718 | +} | |
| 1719 | + | |
| 1720 | +/** | |
| 1721 | + * Item save metadata | |
| 1722 | + * | |
| 1723 | + * @param int $post_id Post ID. | |
| 1724 | + * @param object $post Post data. | |
| 1725 | + */ | |
| 1726 | +function item_save_metadata( $post_id, $post ) { | |
| 1727 | + global $usces, $wpdb; | |
| 1728 | + | |
| 1729 | + $message = ''; | |
| 1730 | + $item_data = wel_get_item( $post_id, false ); | |
| 1731 | + $args = array( | |
| 1732 | + 'usces_nonce' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1733 | + 'itemCode' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1734 | + 'itemName' => FILTER_DEFAULT, | |
| 1735 | + 'itemRestriction' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1736 | + 'itemPointrate' => FILTER_VALIDATE_INT, | |
| 1737 | + 'itemGpNum1' => FILTER_VALIDATE_INT, | |
| 1738 | + 'itemGpNum2' => FILTER_VALIDATE_INT, | |
| 1739 | + 'itemGpNum3' => FILTER_VALIDATE_INT, | |
| 1740 | + 'itemGpDis1' => FILTER_VALIDATE_INT, | |
| 1741 | + 'itemGpDis2' => FILTER_VALIDATE_INT, | |
| 1742 | + 'itemGpDis3' => FILTER_VALIDATE_INT, | |
| 1743 | + 'itemOrderAcceptable' => FILTER_DEFAULT, | |
| 1744 | + 'itemShipping' => FILTER_VALIDATE_INT, | |
| 1745 | + 'itemDeliveryMethod' => array( | |
| 1746 | + 'filter' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1747 | + 'flags' => FILTER_REQUIRE_ARRAY, | |
| 1748 | + ), | |
| 1749 | + 'itemShippingCharge' => FILTER_VALIDATE_INT, | |
| 1750 | + 'itemIndividualSCharge' => FILTER_DEFAULT, | |
| 1751 | + 'item_charging_type' => FILTER_VALIDATE_INT, | |
| 1752 | + 'item_division' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1753 | + 'dlseller_date' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1754 | + 'dlseller_file' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1755 | + 'dlseller_interval' => FILTER_VALIDATE_INT, | |
| 1756 | + 'dlseller_validity' => FILTER_VALIDATE_INT, | |
| 1757 | + 'dlseller_version' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1758 | + 'dlseller_author' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1759 | + 'dlseller_purchases' => FILTER_VALIDATE_INT, | |
| 1760 | + 'dlseller_downloads' => FILTER_VALIDATE_INT, | |
| 1761 | + 'item_chargingday' => FILTER_DEFAULT, | |
| 1762 | + 'item_frequency' => FILTER_DEFAULT, | |
| 1763 | + 'wcad_regular_unit' => FILTER_DEFAULT, | |
| 1764 | + 'wcad_regular_interval' => FILTER_DEFAULT, | |
| 1765 | + 'wcad_regular_frequency' => FILTER_DEFAULT, | |
| 1766 | + 'select_sku_switch' => FILTER_VALIDATE_INT, | |
| 1767 | + 'select_sku_display' => FILTER_VALIDATE_INT, | |
| 1768 | + 'select_sku' => array( | |
| 1769 | + 'filter' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1770 | + 'flags' => FILTER_REQUIRE_ARRAY, | |
| 1771 | + ), | |
| 1772 | + 'deferred_payment_propriety' => FILTER_VALIDATE_INT, | |
| 1773 | + 'atodene_propriety' => FILTER_VALIDATE_INT, | |
| 1774 | + 'structuredDataSku' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1775 | + 'lower_limit' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1776 | + 'popularity' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1777 | + 'main_price' => FILTER_SANITIZE_SPECIAL_CHARS, | |
| 1778 | + 'itemPicts' => FILTER_DEFAULT, | |
| 1779 | + 'itemAdvanced' => array( | |
| 1780 | + 'filter' => FILTER_DEFAULT, | |
| 1781 | + 'flags' => FILTER_REQUIRE_ARRAY, | |
| 1782 | + ), | |
| 1783 | + 'itemsku' => array( | |
| 1784 | + 'filter' => FILTER_DEFAULT, | |
| 1785 | + 'flags' => FILTER_REQUIRE_ARRAY, | |
| 1786 | + ), | |
| 1787 | + 'itemopt' => array( | |
| 1788 | + 'filter' => FILTER_DEFAULT, | |
| 1789 | + 'flags' => FILTER_REQUIRE_ARRAY, | |
| 1790 | + ), | |
| 1791 | + ); | |
| 1792 | + | |
| 1793 | + $inputs = filter_input_array( INPUT_POST, $args ); | |
| 1794 | + $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_SPECIAL_CHARS ); | |
| 1795 | + // Permission check. | |
| 1796 | + if ( 'usces_itemedit' === $page || 'usces_itemnew' === $page ) { | |
| 1797 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
| 1798 | + $usces->set_action_status( 'error', 'ERROR : ' . __( 'Sorry, you do not have the right to edit this post.' ) ); | |
| 1799 | + return $post_id; | |
| 1800 | + } | |
| 1801 | + | |
| 1802 | + // Do nothing when saving auto-draft. | |
| 1803 | + if ( isset( $post->post_status ) && 'auto-draft' === $post->post_status ) { | |
| 1804 | + return $post_id; | |
| 1805 | + } | |
| 1806 | + $usces->set_item_mime( $post_id, 'item' ); | |
| 1807 | + | |
| 1808 | + } else { | |
| 1809 | + | |
| 1810 | + return $post_id; | |
| 1811 | + | |
| 1812 | + } | |
| 1813 | + | |
| 1814 | + if ( ! isset( $inputs['usces_nonce'] ) || ! wp_verify_nonce( $inputs['usces_nonce'], 'usc-e-shop' ) ) { | |
| 1815 | + return $post_id; | |
| 1816 | + } | |
| 1817 | + | |
| 1818 | + // Check if it is an automatic save routine. If so, do not submit the form (do nothing). | |
| 1819 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
| 1820 | + return $post_id; | |
| 1821 | + } | |
| 1822 | + | |
| 1823 | + // Do nothing when saving other plugins. | |
| 1824 | + if ( isset( $post->post_type ) && 'post' !== $post->post_type ) { | |
| 1825 | + return $post_id; | |
| 1826 | + } | |
| 1827 | + | |
| 1828 | + if ( preg_match( '/[^0-9a-zA-Z\-_]/', $inputs['itemCode'] ) ) { | |
| 1829 | + // Do nothing. | |
| 1830 | + } | |
| 1831 | + | |
| 1832 | + if ( empty( $inputs['itemCode'] ) ) { | |
| 1833 | + $inputs['itemCode'] = ''; | |
| 1834 | + $message .= __( 'Product code has not been entered.', 'usces' ) . '<br />'; | |
| 1835 | + } elseif ( $res = usces_is_same_itemcode( $post_id, $inputs['itemCode'] ) ) { | |
| 1836 | + $message .= 'post_ID '; | |
| 1837 | + foreach ( $res as $postid ) { | |
| 1838 | + $message .= $postid . ', '; | |
| 1839 | + } | |
| 1840 | + $message .= __( 'Same product code is registered here.', 'usces' ) . '<br />'; | |
| 1841 | + $usces->set_action_status( 'error', 'ERROR : ' . $message ); | |
| 1842 | + } | |
| 1843 | + $item_data['itemCode'] = $inputs['itemCode']; | |
| 1844 | + | |
| 1845 | + if ( null !== $inputs['itemName'] ) { | |
| 1846 | + $item_data['itemName'] = trim( $inputs['itemName'] ); | |
| 1847 | + } | |
| 1848 | + if ( null !== $inputs['itemRestriction'] ) { | |
| 1849 | + $item_data['itemRestriction'] = trim( $inputs['itemRestriction'] ); | |
| 1850 | + } | |
| 1851 | + if ( null !== $inputs['itemPointrate'] ) { | |
| 1852 | + $item_data['itemPointrate'] = (int) $inputs['itemPointrate']; | |
| 1853 | + } | |
| 1854 | + if ( null !== $inputs['itemGpNum1'] ) { | |
| 1855 | + $item_data['itemGpNum1'] = (int) $inputs['itemGpNum1']; | |
| 1856 | + } | |
| 1857 | + if ( null !== $inputs['itemGpNum2'] ) { | |
| 1858 | + $item_data['itemGpNum2'] = (int) $inputs['itemGpNum2']; | |
| 1859 | + } | |
| 1860 | + if ( null !== $inputs['itemGpNum3'] ) { | |
| 1861 | + $item_data['itemGpNum3'] = (int) $inputs['itemGpNum3']; | |
| 1862 | + } | |
| 1863 | + if ( null !== $inputs['itemGpDis1'] ) { | |
| 1864 | + $item_data['itemGpDis1'] = (int) $inputs['itemGpDis1']; | |
| 1865 | + } | |
| 1866 | + if ( null !== $inputs['itemGpDis2'] ) { | |
| 1867 | + $item_data['itemGpDis2'] = (int) $inputs['itemGpDis2']; | |
| 1868 | + } | |
| 1869 | + if ( null !== $inputs['itemGpDis3'] ) { | |
| 1870 | + $item_data['itemGpDis3'] = (int) $inputs['itemGpDis3']; | |
| 1871 | + } | |
| 1872 | + | |
| 1873 | + $item_data['itemOrderAcceptable'] = null !== $inputs['itemOrderAcceptable'] ? 1 : 0; | |
| 1874 | + | |
| 1875 | + if ( null !== $inputs['itemShipping'] ) { | |
| 1876 | + $item_data['itemShipping'] = (int) $inputs['itemShipping']; | |
| 1877 | + } | |
| 1878 | + if ( null !== $inputs['itemDeliveryMethod'] ) { | |
| 1879 | + $dmethod = array(); | |
| 1880 | + foreach ( (array) $inputs['itemDeliveryMethod'] as $dmid ) { | |
| 1881 | + $dmethod[] = $dmid; | |
| 1882 | + } | |
| 1883 | + $item_data['itemDeliveryMethod'] = $dmethod; | |
| 1884 | + } | |
| 1885 | + if ( null !== $inputs['itemShippingCharge'] ) { | |
| 1886 | + $item_data['itemShippingCharge'] = (int) $inputs['itemShippingCharge']; | |
| 1887 | + } | |
| 1888 | + | |
| 1889 | + $item_data['itemIndividualSCharge'] = null !== $inputs['itemIndividualSCharge'] ? 1 : 0; | |
| 1890 | + | |
| 1891 | + $options = get_option( 'usces', array() ); | |
| 1892 | + $acting_settings = ( isset( $options['acting_settings'] ) ) ? $options['acting_settings'] : array(); | |
| 1893 | + if ( isset( $acting_settings['welcart'] ) && isset( $acting_settings['welcart']['atodene_byitem'] ) && 'on' === $acting_settings['welcart']['atodene_byitem'] ) { | |
| 1894 | + $item_data['atodene_propriety'] = null !== $inputs['atodene_propriety'] ? (int) $inputs['atodene_propriety'] : 0; | |
| 1895 | + } | |
| 1896 | + $options_ex = get_option( 'usces_ex', array() ); | |
| 1897 | + $system_settings = ( isset( $options_ex['system'] ) ) ? $options_ex['system'] : array(); | |
| 1898 | + if ( isset( $system_settings['atobaraicsv'] ) && isset( $system_settings['atobaraicsv']['each_item'] ) && 1 === (int) $system_settings['atobaraicsv']['each_item'] ) { | |
| 1899 | + $item_data['atobarai_propriety'] = null !== $inputs['deferred_payment_propriety'] ? (int) $inputs['deferred_payment_propriety'] : 0; | |
| 1900 | + } | |
| 1901 | + | |
| 1902 | + if ( 1 === (int) USCES_STRUCTURED_DATA_PRODUCT::$opts['status'] ) { | |
| 1903 | + $item_data['structuredDataSku'] = ( isset( $inputs['structuredDataSku'] ) ) ? trim( $inputs['structuredDataSku'] ) : ''; | |
| 1904 | + } | |
| 1905 | + | |
| 1906 | + wel_update_item_data( $item_data, $post_id, true ); | |
| 1907 | + $item_data = wel_get_item( $post_id, false ); | |
| 1908 | + | |
| 1909 | + // SKU. | |
| 1910 | + if ( null !== $inputs['itemsku'] ) { | |
| 1911 | + | |
| 1912 | + $meta_ids = array(); | |
| 1913 | + $codes = array(); | |
| 1914 | + $uniq_code = false; | |
| 1915 | + $irreg_code = false; | |
| 1916 | + $irreg_price = false; | |
| 1917 | + | |
| 1918 | + $skus = wel_get_skus( $post_id, 'meta_id', false ); | |
| 1919 | + | |
| 1920 | + foreach ( $inputs['itemsku'] as $mid => $temp ) { | |
| 1921 | + $meta_ids[] = $mid; | |
| 1922 | + } | |
| 1923 | + $meta_ids = array_unique( $meta_ids ); | |
| 1924 | + foreach ( $meta_ids as $meta_id ) { | |
| 1925 | + | |
| 1926 | + $skucode = isset( $inputs['itemsku'][ $meta_id ]['key'] ) ? trim( $inputs['itemsku'][ $meta_id ]['key'] ) : ''; | |
| 1927 | + $msgsku = apply_filters( 'usces_filter_before_item_save_metadata_sku', null, $post_id, $meta_id, $skucode ); | |
| 1928 | + if ( ! empty( $msgsku ) ) { | |
| 1929 | + $message .= $msgsku; | |
| 1930 | + continue; | |
| 1931 | + } | |
| 1932 | + | |
| 1933 | + $skucprice = isset( $inputs['itemsku'][ $meta_id ]['cprice'] ) ? trim( $inputs['itemsku'][ $meta_id ]['cprice'] ) : 0; | |
| 1934 | + $skuprice = isset( $inputs['itemsku'][ $meta_id ]['price'] ) ? trim( $inputs['itemsku'][ $meta_id ]['price'] ) : 0; | |
| 1935 | + $skustocknum = isset( $inputs['itemsku'][ $meta_id ]['zaikonum'] ) ? trim( $inputs['itemsku'][ $meta_id ]['zaikonum'] ) : 0; | |
| 1936 | + $skustock = isset( $inputs['itemsku'][ $meta_id ]['zaiko'] ) ? (int) $inputs['itemsku'][ $meta_id ]['zaiko'] : ''; | |
| 1937 | + $skuname = isset( $inputs['itemsku'][ $meta_id ]['skudisp'] ) ? trim( $inputs['itemsku'][ $meta_id ]['skudisp'] ) : ''; | |
| 1938 | + $skuunit = isset( $inputs['itemsku'][ $meta_id ]['skuunit'] ) ? trim( $inputs['itemsku'][ $meta_id ]['skuunit'] ) : ''; | |
| 1939 | + $skugp = isset( $inputs['itemsku'][ $meta_id ]['skugptekiyo'] ) ? (int) $inputs['itemsku'][ $meta_id ]['skugptekiyo'] : 0; | |
| 1940 | + $skusort = isset( $inputs['itemsku'][ $meta_id ]['sort'] ) ? $inputs['itemsku'][ $meta_id ]['sort'] : 0; | |
| 1941 | + $skutaxrate = isset( $inputs['itemsku'][ $meta_id ]['applicable_taxrate'] ) ? $inputs['itemsku'][ $meta_id ]['applicable_taxrate'] : ''; | |
| 1942 | + | |
| 1943 | + $sku = $skus[ $meta_id ]; | |
| 1944 | + | |
| 1945 | + $sku['code'] = $skucode; | |
| 1946 | + $sku['name'] = $skuname; | |
| 1947 | + $sku['cprice'] = $skucprice; | |
| 1948 | + $sku['price'] = $skuprice; | |
| 1949 | + $sku['unit'] = $skuunit; | |
| 1950 | + $sku['stocknum'] = $skustocknum; | |
| 1951 | + $sku['stock'] = $skustock; | |
| 1952 | + $sku['gp'] = $skugp; | |
| 1953 | + $sku['sort'] = $skusort; | |
| 1954 | + if ( ! empty( $skutaxrate ) ) { | |
| 1955 | + $sku['taxrate'] = $skutaxrate; | |
| 1956 | + } | |
| 1957 | + $sku = $usces->stripslashes_deep_post( $sku ); | |
| 1958 | + $sku = apply_filters( 'usces_filter_item_save_sku_metadata', $sku, $meta_id ); | |
| 1959 | + | |
| 1960 | + wel_update_sku_data_by_id( $meta_id, $post_id, $sku ); | |
| 1961 | + | |
| 1962 | + if ( in_array( $skucode, $codes ) ) { | |
| 1963 | + $uniq_code = true; | |
| 1964 | + } | |
| 1965 | + | |
| 1966 | + if ( WCUtils::is_blank( $skucode ) ) { | |
| 1967 | + $irreg_code = true; | |
| 1968 | + } | |
| 1969 | + | |
| 1970 | + if ( WCUtils::is_blank( $skuprice ) || preg_match( '/[^0-9.]/', $skuprice ) || 1 < substr_count( $skuprice, '.' ) ) { | |
| 1971 | + $irreg_price = true; | |
| 1972 | + } | |
| 1973 | + | |
| 1974 | + $codes[] = $skucode; | |
| 1975 | + } | |
| 1976 | + | |
| 1977 | + if ( $uniq_code ) { | |
| 1978 | + $message .= __( 'SKU code is duplicated.', 'usces' ) . '<br />'; | |
| 1979 | + } | |
| 1980 | + if ( $irreg_code ) { | |
| 1981 | + $message .= __( 'SKU code is invalid.', 'usces' ) . '<br />'; | |
| 1982 | + } | |
| 1983 | + if ( $irreg_price ) { | |
| 1984 | + $message .= __( 'SKU of invalid selling price exists.', 'usces' ) . '<br />'; | |
| 1985 | + } | |
| 1986 | + } | |
| 1987 | + | |
| 1988 | + // OPT. | |
| 1989 | + if ( null !== $inputs['itemopt'] ) { | |
| 1990 | + $meta_ids = array(); | |
| 1991 | + $names = array(); | |
| 1992 | + $uniq_name = false; | |
| 1993 | + $irreg_name = false; | |
| 1994 | + $irreg_value = false; | |
| 1995 | + | |
| 1996 | + $opts = wel_get_opts( $post_id, 'meta_id', false ); | |
| 1997 | + | |
| 1998 | + foreach ( $inputs['itemopt'] as $mid => $temp ) { | |
| 1999 | + $meta_ids[] = $mid; | |
| 2000 | + } | |
| 2001 | + $meta_ids = array_unique( $meta_ids ); | |
| 2002 | + foreach ( $meta_ids as $meta_id ) { | |
| 2003 | + | |
| 2004 | + $optname = isset( $inputs['itemopt'][ $meta_id ]['name'] ) ? $inputs['itemopt'][ $meta_id ]['name'] : ''; | |
| 2005 | + $optmeans = isset( $inputs['itemopt'][ $meta_id ]['means'] ) ? (int) $inputs['itemopt'][ $meta_id ]['means'] : 0; | |
| 2006 | + $optessential = isset( $inputs['itemopt'][ $meta_id ]['essential'] ) ? $inputs['itemopt'][ $meta_id ]['essential'] : 0; | |
| 2007 | + $optsort = isset( $inputs['itemopt'][ $meta_id ]['sort'] ) ? $inputs['itemopt'][ $meta_id ]['sort'] : 0; | |
| 2008 | + $optvalue = isset( $inputs['itemopt'][ $meta_id ]['value'] ) ? trim( $inputs['itemopt'][ $meta_id ]['value'] ) : ''; | |
| 2009 | + | |
| 2010 | + $opt = $opts[ $meta_id ]; | |
| 2011 | + | |
| 2012 | + $opt['name'] = str_replace( "\\", '', $optname ); | |
| 2013 | + $opt['value'] = str_replace( "\\", '', $optvalue ); | |
| 2014 | + $opt['means'] = $optmeans; | |
| 2015 | + $opt['essential'] = $optessential; | |
| 2016 | + $opt['sort'] = $optsort; | |
| 2017 | + | |
| 2018 | + $opt = $usces->stripslashes_deep_post( $opt ); | |
| 2019 | + | |
| 2020 | + wel_update_opt_data_by_id( $meta_id, $post_id, $opt ); | |
| 2021 | + | |
| 2022 | + if ( in_array( $optname, $names ) ) { | |
| 2023 | + $uniq_name = true; | |
| 2024 | + } | |
| 2025 | + | |
| 2026 | + if ( WCUtils::is_blank( $optname ) ) { | |
| 2027 | + $irreg_name = true; | |
| 2028 | + } | |
| 2029 | + | |
| 2030 | + if ( WCUtils::is_blank( $optvalue ) && 1 >= $optmeans ) { | |
| 2031 | + $irreg_value = true; | |
| 2032 | + } | |
| 2033 | + | |
| 2034 | + $names[] = $optname; | |
| 2035 | + } | |
| 2036 | + | |
| 2037 | + if ( $uniq_name ) { | |
| 2038 | + $message .= __( 'Commodity option option name duplicates exist.', 'usces' ) . '<br />'; | |
| 2039 | + } | |
| 2040 | + if ( $irreg_name ) { | |
| 2041 | + $message .= __( 'Commodity option not entered there is the option name.', 'usces' ) . '<br />'; | |
| 2042 | + } | |
| 2043 | + if ( $irreg_value ) { | |
| 2044 | + $message .= __( "If you select 'single select' and 'multi-select' the trade option, please enter the select value.", 'usces' ) . '<br />'; | |
| 2045 | + } | |
| 2046 | + } | |
| 2047 | + | |
| 2048 | + do_action( 'usces_action_save_product', $post_id, $post ); | |
| 2049 | + $message = apply_filters( 'usces_filter_save_product_message', $message, $post_id ); | |
| 2050 | + | |
| 2051 | + if ( $message ) { | |
| 2052 | + $usces->set_action_status( 'error', 'ERROR : ' . $message ); | |
| 2053 | + } else { | |
| 2054 | + $usces->set_action_status( 'success', __( 'Registration of the product is complete.', 'usces' ) ); | |
| 2055 | + } | |
| 2056 | +} | |
| 2057 | + | |
| 2058 | +/** | |
| 2059 | + * Link replace | |
| 2060 | + * | |
| 2061 | + * @param string $para Parameters. | |
| 2062 | + * @return string | |
| 2063 | + */ | |
| 2064 | +function usces_link_replace( $para ) { | |
| 2065 | + $str = 'admin.php?page=usces_itemedit&'; | |
| 2066 | + $url = preg_replace( '|post\.php\?|i', $str, $para ); | |
| 2067 | + return $url; | |
| 2068 | +} | |
| 2069 | + | |
| 2070 | +/** | |
| 2071 | + * Count posts | |
| 2072 | + * | |
| 2073 | + * @param string $type Type. | |
| 2074 | + * @param string $perm perm. | |
| 2075 | + * @return object | |
| 2076 | + */ | |
| 2077 | +function usces_count_posts( $type = 'post', $perm = '' ) { | |
| 2078 | + global $wpdb; | |
| 2079 | + | |
| 2080 | + $user = wp_get_current_user(); | |
| 2081 | + | |
| 2082 | + $cache_key = $type; | |
| 2083 | + | |
| 2084 | + $query = "SELECT post_status, COUNT( * ) AS `num_posts` FROM {$wpdb->posts} WHERE post_type = %s AND post_mime_type = 'item'"; | |
| 2085 | + if ( 'readable' == $perm && is_user_logged_in() ) { | |
| 2086 | + if ( ! current_user_can( "read_private_{$type}s" ) ) { | |
| 2087 | + $cache_key .= '_' . $perm . '_' . $user->ID; | |
| 2088 | + $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; | |
| 2089 | + } | |
| 2090 | + } | |
| 2091 | + $query .= ' GROUP BY post_status'; | |
| 2092 | + | |
| 2093 | + $count = wp_cache_get( $cache_key, 'counts' ); | |
| 2094 | + if ( false !== $count ) { | |
| 2095 | + $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); | |
| 2096 | + } | |
| 2097 | + | |
| 2098 | + $stats = array(); | |
| 2099 | + foreach ( (array) $count as $row_num => $row ) { | |
| 2100 | + $stats[ $row['post_status'] ] = $row['num_posts']; | |
| 2101 | + } | |
| 2102 | + | |
| 2103 | + $stats = (object) $stats; | |
| 2104 | + wp_cache_set( $cache_key, $stats, 'counts' ); | |
| 2105 | + | |
| 2106 | + return $stats; | |
| 2107 | +} | |
| 2108 | + | |
| 2109 | +/** | |
| 2110 | + * Custom order meta row | |
| 2111 | + * | |
| 2112 | + * @param string $key Key. | |
| 2113 | + * @param array $entry Entry data. | |
| 2114 | + * @return string | |
| 2115 | + */ | |
| 2116 | +function _list_custom_order_meta_row( $key, $entry ) { | |
| 2117 | + $r = ''; | |
| 2118 | + $style = ''; | |
| 2119 | + $key = esc_attr( $key ); | |
| 2120 | + | |
| 2121 | + $name = esc_attr( $entry['name'] ); | |
| 2122 | + $means = get_option( 'usces_custom_order_select', array() ); | |
| 2123 | + $meansoption = ''; | |
| 2124 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 2125 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '"' . selected( $meankey, $entry['means'], false ) . '>' . esc_html( $meanvalue ) . "</option>\n"; | |
| 2126 | + } | |
| 2127 | + $essential = ( 1 === (int) $entry['essential'] ) ? ' checked="checked"' : ''; | |
| 2128 | + $value = ''; | |
| 2129 | + if ( is_array( $entry['value'] ) ) { | |
| 2130 | + foreach ( $entry['value'] as $k => $v ) { | |
| 2131 | + $value .= $v . "\n"; | |
| 2132 | + } | |
| 2133 | + } | |
| 2134 | + $value = esc_attr( trim( $value ) ); | |
| 2135 | + | |
| 2136 | + $r .= "\n\t<tr id=\"csod-{$key}\" class=\"{$style}\">"; | |
| 2137 | + $r .= "\n\t\t<td class=\"left\"><div><input type=\"text\" name=\"csod[{$key}][key]\" id=\"csod[{$key}][key]\" class=\"optname\" size=\"20\" value=\"{$key}\" readonly /></div>"; | |
| 2138 | + $r .= "\n\t\t<div><input type=\"text\" name=\"csod[{$key}][name]\" id=\"csod[{$key}][name]\" class=\"optname\" size=\"20\" value=\"{$name}\" /></div>"; | |
| 2139 | + $r .= "\n\t\t<div class=\"optcheck\"><select name=\"csod[{$key}][means]\" id=\"csod[{$key}][means]\">" . $meansoption . "</select>\n"; | |
| 2140 | + $r .= "<input type=\"checkbox\" name=\"csod[{$key}][essential]\" id=\"csod[{$key}][essential]\" value=\"1\"{$essential} /><label for=\"csod[{$key}][essential]\">" . esc_html__( 'Required', 'usces' ) . '</label></div>'; | |
| 2141 | + $r .= "\n\t\t<div class=\"submit\"><input type=\"button\" class=\"button\" name=\"del_csod[{$key}]\" id=\"del_csod[{$key}]\" value=\"" . esc_attr__( 'Delete' ) . "\" onclick=\"customField.delOrder('{$key}');\" />"; | |
| 2142 | + $r .= "\n\t\t<input type=\"button\" class=\"button\" name=\"upd_csod[{$key}]\" id=\"upd_csod[{$key}]\" value=\"" . esc_attr__( 'Update' ) . "\" onclick=\"customField.updOrder('{$key}');\" /></div>"; | |
| 2143 | + $r .= "\n\t\t<div id=\"csod_loading-{$key}\" class=\"meta_submit_loading\"></div>"; | |
| 2144 | + $r .= '</td>'; | |
| 2145 | + $r .= "\n\t\t<td class=\"item-opt-value\"><textarea name=\"csod[{$key}][value]\" id=\"csod[{$key}][value]\" class=\"optvalue\">{$value}</textarea></td>\n\t</tr>"; | |
| 2146 | + return $r; | |
| 2147 | +} | |
| 2148 | + | |
| 2149 | +/** | |
| 2150 | + * Has custom field meta | |
| 2151 | + * | |
| 2152 | + * @param string $fieldname Field name. | |
| 2153 | + * @return mixed | |
| 2154 | + */ | |
| 2155 | +function usces_has_custom_field_meta( $fieldname ) { | |
| 2156 | + switch ( $fieldname ) { | |
| 2157 | + case 'order': | |
| 2158 | + $field = 'usces_custom_order_field'; | |
| 2159 | + break; | |
| 2160 | + case 'customer': | |
| 2161 | + $field = 'usces_custom_customer_field'; | |
| 2162 | + break; | |
| 2163 | + case 'delivery': | |
| 2164 | + $field = 'usces_custom_delivery_field'; | |
| 2165 | + break; | |
| 2166 | + case 'member': | |
| 2167 | + $field = 'usces_custom_member_field'; | |
| 2168 | + break; | |
| 2169 | + case 'admin_member': | |
| 2170 | + $field = 'usces_admin_custom_member_field'; | |
| 2171 | + break; | |
| 2172 | + default: | |
| 2173 | + return array(); | |
| 2174 | + } | |
| 2175 | + $fields = get_option( $field ); | |
| 2176 | + if ( empty( $fields ) ) { | |
| 2177 | + $meta = array(); | |
| 2178 | + } elseif ( is_array( $fields ) ) { | |
| 2179 | + $meta = $fields; | |
| 2180 | + } else { | |
| 2181 | + $meta = wel_safe_unserialize( $fields ); | |
| 2182 | + } | |
| 2183 | + return $meta; | |
| 2184 | +} | |
| 2185 | + | |
| 2186 | +/** | |
| 2187 | + * Get info ajax | |
| 2188 | + * | |
| 2189 | + * @return void | |
| 2190 | + */ | |
| 2191 | +function usces_getinfo_ajax() { | |
| 2192 | + global $wp_version; | |
| 2193 | + | |
| 2194 | + $wcex = usces_get_wcex(); | |
| 2195 | + $wcex_str = join( ',', array_map( | |
| 2196 | + function( $key, $values ) { | |
| 2197 | + return $key . '-' . $values['version']; | |
| 2198 | + }, | |
| 2199 | + array_keys( $wcex ), $wcex ) | |
| 2200 | + ); | |
| 2201 | + | |
| 2202 | + $theme_data = wp_get_theme(); | |
| 2203 | + $theme = urlencode( $theme_data->get( 'Name' ) . '-' . $theme_data->get( 'Version' ) ); | |
| 2204 | + | |
| 2205 | + $args = array( | |
| 2206 | + 'timeout' => 30, | |
| 2207 | + 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded' ), | |
| 2208 | + 'body' => array( | |
| 2209 | + 'v' => urlencode( USCES_VERSION ), | |
| 2210 | + 'wcid' => urlencode( get_option( 'usces_wcid' ) ), | |
| 2211 | + 'locale'=> urlencode( get_locale() ), | |
| 2212 | + 'theme' => $theme, | |
| 2213 | + 'wcex' => urlencode( $wcex_str ), | |
| 2214 | + 'wcurl' => urlencode( get_home_url() ) | |
| 2215 | + ) | |
| 2216 | + ); | |
| 2217 | + | |
| 2218 | + $response = wp_remote_post( 'https://www.welcart.com/util/welcart_information2.php', $args ); | |
| 2219 | + | |
| 2220 | + if ( is_wp_error( $response ) ) { | |
| 2221 | + die( 'ERROR' ); | |
| 2222 | + } | |
| 2223 | + | |
| 2224 | + $body = wp_remote_retrieve_body( $response ); | |
| 2225 | + if ( empty( $body ) ) { | |
| 2226 | + die( 'ERROR' ); | |
| 2227 | + } | |
| 2228 | + | |
| 2229 | + $res = ''; | |
| 2230 | + preg_match_all( "/<(title|data)>(.*?)<\/(title|data)>/s", $body, $matches, PREG_SET_ORDER ); | |
| 2231 | + | |
| 2232 | + foreach ( $matches as $match ) { | |
| 2233 | + switch ( $match[1] ) { | |
| 2234 | + case 'title': | |
| 2235 | + $res .= '<div style="text-align: center;border-bottom: 1px dotted #CCCCCC;width: 80%;margin-bottom: 10px;padding-bottom: 3px; margin-right: auto; margin-left: auto;"><strong>' . $match[2] . '</strong></div><ul>'; | |
| 2236 | + break; | |
| 2237 | + case 'data': | |
| 2238 | + $res .= '<li>' . $match[2] . '</li>'; | |
| 2239 | + break; | |
| 2240 | + } | |
| 2241 | + } | |
| 2242 | + $res .= '</ul>'; | |
| 2243 | + | |
| 2244 | + die( $res ); | |
| 2245 | +} | |
| 2246 | + | |
| 2247 | +/** | |
| 2248 | + * Custom field ajax | |
| 2249 | + */ | |
| 2250 | +function custom_field_ajax() { | |
| 2251 | + global $usces; | |
| 2252 | + | |
| 2253 | + check_admin_referer( 'custom_field_ajax', 'wc_nonce' ); | |
| 2254 | + if ( ! current_user_can( 'wel_manage_setting' ) ) { | |
| 2255 | + wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); | |
| 2256 | + } | |
| 2257 | + | |
| 2258 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 2259 | + $data = array( | |
| 2260 | + 'status' => 'OK', | |
| 2261 | + 'msg' => '', | |
| 2262 | + ); | |
| 2263 | + | |
| 2264 | + if ( 'custom_field_ajax' !== $_POST['action'] ) { | |
| 2265 | + $data['status'] = 'NG'; | |
| 2266 | + wp_send_json( $data ); | |
| 2267 | + } | |
| 2268 | + | |
| 2269 | + switch ( $_POST['field'] ) { | |
| 2270 | + case 'order': | |
| 2271 | + $field = 'usces_custom_order_field'; | |
| 2272 | + break; | |
| 2273 | + case 'customer': | |
| 2274 | + $field = 'usces_custom_customer_field'; | |
| 2275 | + break; | |
| 2276 | + case 'delivery': | |
| 2277 | + $field = 'usces_custom_delivery_field'; | |
| 2278 | + break; | |
| 2279 | + case 'member': | |
| 2280 | + $field = 'usces_custom_member_field'; | |
| 2281 | + break; | |
| 2282 | + case 'admin_member': | |
| 2283 | + $field = 'usces_admin_custom_member_field'; | |
| 2284 | + break; | |
| 2285 | + default: | |
| 2286 | + $data['status'] = 'NG'; | |
| 2287 | + wp_send_json( $data ); | |
| 2288 | + } | |
| 2289 | + | |
| 2290 | + $meta = usces_has_custom_field_meta( $_POST['field'] ); | |
| 2291 | + $dupkey = 0; | |
| 2292 | + $dupname = 0; | |
| 2293 | + | |
| 2294 | + if ( isset( $_POST['add'] ) ) { | |
| 2295 | + $newkey = ( isset( $_POST['newkey'] ) ) ? trim( $_POST['newkey'] ) : ''; | |
| 2296 | + $newname = ( isset( $_POST['newname'] ) ) ? trim( $_POST['newname'] ) : ''; | |
| 2297 | + $newmeans = ( isset( $_POST['newmeans'] ) ) ? $_POST['newmeans'] : 0; | |
| 2298 | + $newessential = ( isset( $_POST['newessential'] ) ) ? $_POST['newessential'] : 0; | |
| 2299 | + $newposition = ( isset( $_POST['newposition'] ) ) ? trim( $_POST['newposition'] ) : ''; | |
| 2300 | + | |
| 2301 | + if ( 2 === (int) $newmeans || 5 === (int) $newmeans ) { // Text or Textarea. | |
| 2302 | + $newvalue = ''; | |
| 2303 | + $nv = $newvalue; | |
| 2304 | + $required_entry = ( ! empty( $newkey ) && ! empty( $newname ) ) ? true : false; | |
| 2305 | + } else { | |
| 2306 | + $newvalue = ( isset( $_POST['newvalue'] ) ) ? explode( "\n", trim( $_POST['newvalue'] ) ) : ''; | |
| 2307 | + foreach ( (array) $newvalue as $v ) { | |
| 2308 | + if ( ! WCUtils::is_blank( $v ) ) { | |
| 2309 | + $nv[] = trim( $v ); | |
| 2310 | + } | |
| 2311 | + } | |
| 2312 | + $required_entry = ( ( ! empty( $newvalue ) ) && ! empty( $newkey ) && ! empty( $newname ) ) ? true : false; | |
| 2313 | + } | |
| 2314 | + | |
| 2315 | + if ( ! array_key_exists( $newkey, $meta ) ) { | |
| 2316 | + if ( $required_entry ) { | |
| 2317 | + $meta[ $newkey ]['name'] = $newname; | |
| 2318 | + $meta[ $newkey ]['means'] = $newmeans; | |
| 2319 | + $meta[ $newkey ]['essential'] = $newessential; | |
| 2320 | + $meta[ $newkey ]['value'] = $nv; | |
| 2321 | + if ( ! WCUtils::is_blank( $newposition ) ) { | |
| 2322 | + $meta[ $newkey ]['position'] = $newposition; | |
| 2323 | + } elseif ( ( 'admin_member' === $_POST['field'] ) && WCUtils::is_blank( $newposition ) ) { | |
| 2324 | + $meta[ $newkey ]['position'] = 'fax_after'; | |
| 2325 | + } | |
| 2326 | + update_option( $field, $meta ); | |
| 2327 | + } | |
| 2328 | + } else { | |
| 2329 | + $dupkey = 1; | |
| 2330 | + } | |
| 2331 | + | |
| 2332 | + } elseif ( isset( $_POST['update'] ) ) { | |
| 2333 | + $key = ( isset( $_POST['key'] ) ) ? trim( $_POST['key'] ) : ''; | |
| 2334 | + $name = ( isset( $_POST['name'] ) ) ? trim( $_POST['name'] ) : ''; | |
| 2335 | + $means = ( isset( $_POST['means'] ) ) ? $_POST['means'] : 0; | |
| 2336 | + $essential = ( isset( $_POST['essential'] ) ) ? $_POST['essential'] : 0; | |
| 2337 | + $position = ( isset( $_POST['position'] ) ) ? trim( $_POST['position'] ) : ''; | |
| 2338 | + | |
| 2339 | + if ( 2 === (int) $means || 5 === (int) $means ) { // Text or Textarea. | |
| 2340 | + $value = ''; | |
| 2341 | + $nv = $value; | |
| 2342 | + $required_entry = ( ! empty( $key ) && ! empty( $name ) ) ? true : false; | |
| 2343 | + | |
| 2344 | + } else { | |
| 2345 | + $value = ( isset( $_POST['value'] ) ) ? explode( "\n", trim( $_POST['value'] ) ) : ''; | |
| 2346 | + foreach ( (array) $value as $v ) { | |
| 2347 | + if ( ! WCUtils::is_blank( $v ) ) { | |
| 2348 | + $nv[] = trim( $v ); | |
| 2349 | + } | |
| 2350 | + } | |
| 2351 | + $required_entry = ( ( ! empty( $value ) ) && ! empty( $key ) && ! empty( $name ) ) ? true : false; | |
| 2352 | + } | |
| 2353 | + | |
| 2354 | + if ( $required_entry ) { | |
| 2355 | + $meta[ $key ]['name'] = $name; | |
| 2356 | + $meta[ $key ]['means'] = $means; | |
| 2357 | + $meta[ $key ]['essential'] = $essential; | |
| 2358 | + $meta[ $key ]['value'] = $nv; | |
| 2359 | + if ( ! WCUtils::is_blank( $position ) ) { | |
| 2360 | + $meta[ $key ]['position'] = $position; | |
| 2361 | + } | |
| 2362 | + update_option( $field, $meta ); | |
| 2363 | + } | |
| 2364 | + | |
| 2365 | + } elseif ( isset( $_POST['delete'] ) ) { | |
| 2366 | + $key = ( isset( $_POST['key'] ) ) ? trim( $_POST['key'] ) : ''; | |
| 2367 | + unset( $meta[ $key ] ); | |
| 2368 | + update_option( $field, $meta ); | |
| 2369 | + } | |
| 2370 | + | |
| 2371 | + $r = ''; | |
| 2372 | + switch ( $_POST['field'] ) { | |
| 2373 | + case 'order': | |
| 2374 | + foreach ( $meta as $key => $entry ) { | |
| 2375 | + $r .= _list_custom_order_meta_row( $key, $entry ); | |
| 2376 | + } | |
| 2377 | + break; | |
| 2378 | + case 'customer': | |
| 2379 | + foreach ( $meta as $key => $entry ) { | |
| 2380 | + $r .= _list_custom_customer_meta_row( $key, $entry ); | |
| 2381 | + } | |
| 2382 | + break; | |
| 2383 | + case 'delivery': | |
| 2384 | + foreach ( $meta as $key => $entry ) { | |
| 2385 | + $r .= _list_custom_delivery_meta_row( $key, $entry ); | |
| 2386 | + } | |
| 2387 | + break; | |
| 2388 | + case 'member': | |
| 2389 | + foreach ( $meta as $key => $entry ) { | |
| 2390 | + $r .= _list_custom_member_meta_row( $key, $entry ); | |
| 2391 | + } | |
| 2392 | + break; | |
| 2393 | + case 'admin_member': | |
| 2394 | + foreach ( $meta as $key => $entry ) { | |
| 2395 | + $r .= _list_admin_custom_member_meta_row( $key, $entry ); | |
| 2396 | + } | |
| 2397 | + break; | |
| 2398 | + } | |
| 2399 | + | |
| 2400 | + $data['list'] = $r; | |
| 2401 | + $data['dupkey'] = $dupkey; | |
| 2402 | + $data['dupname'] = $dupname; | |
| 2403 | + wp_send_json( $data ); | |
| 2404 | +} | |
| 2405 | + | |
| 2406 | +/** | |
| 2407 | + * List custom customer meta row | |
| 2408 | + * | |
| 2409 | + * @param string $key Key. | |
| 2410 | + * @param array $entry Entry data. | |
| 2411 | + * @return string | |
| 2412 | + */ | |
| 2413 | +function _list_custom_customer_meta_row( $key, $entry ) { | |
| 2414 | + $r = ''; | |
| 2415 | + $style = ''; | |
| 2416 | + $key = esc_attr( $key ); | |
| 2417 | + | |
| 2418 | + $name = esc_attr( $entry['name'] ); | |
| 2419 | + $means = get_option( 'usces_custom_customer_select', array() ); | |
| 2420 | + $meansoption = ''; | |
| 2421 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 2422 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '"' . selected( $meankey, $entry['means'], false ) . '>' . esc_html( $meanvalue ) . "</option>\n"; | |
| 2423 | + } | |
| 2424 | + $essential = ( 1 === (int) $entry['essential'] ) ? ' checked="checked"' : ''; | |
| 2425 | + $value = ''; | |
| 2426 | + if ( is_array( $entry['value'] ) ) { | |
| 2427 | + foreach ( $entry['value'] as $k => $v ) { | |
| 2428 | + $value .= $v . "\n"; | |
| 2429 | + } | |
| 2430 | + } | |
| 2431 | + $value = esc_attr( trim( $value ) ); | |
| 2432 | + $positions = get_option( 'usces_custom_field_position_select', array() ); | |
| 2433 | + $positionsoption = ''; | |
| 2434 | + foreach ( $positions as $poskey => $posvalue ) { | |
| 2435 | + $positionsoption .= '<option value="' . esc_attr( $poskey ) . '"' . selected( $poskey, $entry['position'], false ) . '>' . esc_attr( $posvalue ) . "</option>\n"; | |
| 2436 | + } | |
| 2437 | + | |
| 2438 | + $r .= "\n\t<tr id=\"cscs-{$key}\" class=\"{$style}\">"; | |
| 2439 | + $r .= "\n\t\t<td class=\"left\"><div><input type=\"text\" name=\"cscs[{$key}][key]\" id=\"cscs[{$key}][key]\" class=\"optname\" size=\"20\" value=\"{$key}\" readonly /></div>"; | |
| 2440 | + $r .= "\n\t\t<div><input type=\"text\" name=\"cscs[{$key}][name]\" id=\"cscs[{$key}][name]\" class=\"optname\" size=\"20\" value=\"{$name}\" /></div>"; | |
| 2441 | + $r .= "\n\t\t<div class=\"optcheck\"><select name=\"cscs[{$key}][means]\" id=\"cscs[{$key}][means]\">" . $meansoption . "</select>\n"; | |
| 2442 | + $r .= "<input type=\"checkbox\" name=\"cscs[{$key}][essential]\" id=\"cscs[{$key}][essential]\" value=\"1\"{$essential} /><label for=\"cscs[{$key}][essential]\">" . esc_html__( 'Required', 'usces' ) . "</label>\n"; | |
| 2443 | + $r .= "<select name=\"cscs[{$key}][position]\" id=\"cscs[{$key}][position]\">" . $positionsoption . '</select></div>'; | |
| 2444 | + $r .= "\n\t\t<div class=\"submit\"><input type=\"button\" class=\"button\" name=\"del_cscs[{$key}]\" id=\"del_cscs[{$key}]\" value=\"" . esc_attr__( 'Delete' ) . "\" onclick=\"customField.delCustomer('{$key}');\" />"; | |
| 2445 | + $r .= "\n\t\t<input type=\"button\" class=\"button\" name=\"upd_cscs[{$key}]\" id=\"upd_cscs[{$key}]\" value=\"" . esc_attr__( 'Update' ) . "\" onclick=\"customField.updCustomer('{$key}');\" /></div>"; | |
| 2446 | + $r .= "\n\t\t<div id=\"cscs_loading-{$key}\" class=\"meta_submit_loading\"></div>"; | |
| 2447 | + $r .= '</td>'; | |
| 2448 | + $r .= "\n\t\t<td class=\"item-opt-value\"><textarea name=\"cscs[{$key}][value]\" id=\"cscs[{$key}][value]\" class=\"optvalue\">{$value}</textarea></td>\n\t</tr>"; | |
| 2449 | + return $r; | |
| 2450 | +} | |
| 2451 | + | |
| 2452 | +/** | |
| 2453 | + * List custom delivery meta row | |
| 2454 | + * | |
| 2455 | + * @param string $key Key. | |
| 2456 | + * @param array $entry Entry data. | |
| 2457 | + * @return string | |
| 2458 | + */ | |
| 2459 | +function _list_custom_delivery_meta_row( $key, $entry ) { | |
| 2460 | + $r = ''; | |
| 2461 | + $style = ''; | |
| 2462 | + $key = esc_attr( $key ); | |
| 2463 | + | |
| 2464 | + $name = esc_attr( $entry['name'] ); | |
| 2465 | + $means = get_option( 'usces_custom_delivery_select', array() ); | |
| 2466 | + $meansoption = ''; | |
| 2467 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 2468 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '"' . selected( $meankey, $entry['means'], false ) . '>' . esc_html( $meanvalue ) . "</option>\n"; | |
| 2469 | + } | |
| 2470 | + $essential = ( 1 === (int) $entry['essential'] ) ? ' checked="checked"' : ''; | |
| 2471 | + $value = ''; | |
| 2472 | + if ( is_array( $entry['value'] ) ) { | |
| 2473 | + foreach ( $entry['value'] as $k => $v ) { | |
| 2474 | + $value .= $v . "\n"; | |
| 2475 | + } | |
| 2476 | + } | |
| 2477 | + $value = esc_attr( trim( $value ) ); | |
| 2478 | + $positions = get_option( 'usces_custom_field_position_select', array() ); | |
| 2479 | + $positionsoption = ''; | |
| 2480 | + foreach ( $positions as $poskey => $posvalue ) { | |
| 2481 | + $positionsoption .= '<option value="' . esc_attr( $poskey ) . '"' . selected( $poskey, $entry['position'], false ) . '>' . esc_attr( $posvalue ) . "</option>\n"; | |
| 2482 | + } | |
| 2483 | + | |
| 2484 | + $r .= "\n\t<tr id=\"csde-{$key}\" class=\"{$style}\">"; | |
| 2485 | + $r .= "\n\t\t<td class=\"left\"><div><input type=\"text\" name=\"csde[{$key}][key]\" id=\"csde[{$key}][key]\" class=\"optname\" size=\"20\" value=\"{$key}\" readonly /></div>"; | |
| 2486 | + $r .= "\n\t\t<div><input type=\"text\" name=\"csde[{$key}][name]\" id=\"csde[{$key}][name]\" class=\"optname\" size=\"20\" value=\"{$name}\" /></div>"; | |
| 2487 | + $r .= "\n\t\t<div class=\"optcheck\"><select name=\"csde[{$key}][means]\" id=\"csde[{$key}][means]\">" . $meansoption . "</select>\n"; | |
| 2488 | + $r .= "<input type=\"checkbox\" name=\"csde[{$key}][essential]\" id=\"csde[{$key}][essential]\" value=\"1\"{$essential} /><label for=\"csde[{$key}][essential]\">" . esc_html__( 'Required', 'usces' ) . "</label>\n"; | |
| 2489 | + $r .= "<select name=\"csde[{$key}][position]\" id=\"csde[{$key}][position]\">" . $positionsoption . '</select></div>'; | |
| 2490 | + $r .= "\n\t\t<div class=\"submit\"><input type=\"button\" class=\"button\" name=\"del_csde[{$key}]\" id=\"del_csde[{$key}]\" value=\"" . esc_attr__( 'Delete' ) . "\" onclick=\"customField.delDelivery('{$key}');\" />"; | |
| 2491 | + $r .= "\n\t\t<input type=\"button\" class=\"button\" name=\"upd_csde[{$key}]\" id=\"upd_csde[{$key}]\" value=\"" . esc_attr__( 'Update' ) . "\" onclick=\"customField.updDelivery('{$key}');\" /></div>"; | |
| 2492 | + $r .= "\n\t\t<div id=\"csde_loading-{$key}\" class=\"meta_submit_loading\"></div>"; | |
| 2493 | + $r .= '</td>'; | |
| 2494 | + $r .= "\n\t\t<td class=\"item-opt-value\"><textarea name=\"csde[{$key}][value]\" id=\"csde[{$key}][value]\" class=\"optvalue\">{$value}</textarea></td>\n\t</tr>"; | |
| 2495 | + return $r; | |
| 2496 | +} | |
| 2497 | + | |
| 2498 | +/** | |
| 2499 | + * List custom member meta row | |
| 2500 | + * | |
| 2501 | + * @param string $key Key. | |
| 2502 | + * @param array $entry Entry data. | |
| 2503 | + * @return string | |
| 2504 | + */ | |
| 2505 | +function _list_custom_member_meta_row( $key, $entry ) { | |
| 2506 | + $r = ''; | |
| 2507 | + $style = ''; | |
| 2508 | + $key = esc_attr( $key ); | |
| 2509 | + | |
| 2510 | + $name = esc_attr( $entry['name'] ); | |
| 2511 | + $means = get_option( 'usces_custom_member_select', array() ); | |
| 2512 | + $meansoption = ''; | |
| 2513 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 2514 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '"' . selected( $meankey, $entry['means'], false ) . '>' . esc_html( $meanvalue ) . "</option>\n"; | |
| 2515 | + } | |
| 2516 | + $essential = ( 1 === (int) $entry['essential'] ) ? ' checked="checked"' : ''; | |
| 2517 | + $value = ''; | |
| 2518 | + if ( is_array( $entry['value'] ) ) { | |
| 2519 | + foreach ( $entry['value'] as $k => $v ) { | |
| 2520 | + $value .= $v . "\n"; | |
| 2521 | + } | |
| 2522 | + } | |
| 2523 | + $value = esc_attr( trim( $value ) ); | |
| 2524 | + $positions = get_option( 'usces_custom_field_position_select', array() ); | |
| 2525 | + $positionsoption = ''; | |
| 2526 | + foreach ( $positions as $poskey => $posvalue ) { | |
| 2527 | + $positionsoption .= '<option value="' . esc_attr( $poskey ) . '"' . selected( $poskey, $entry['position'], false ) . '>' . esc_attr( $posvalue ) . "</option>\n"; | |
| 2528 | + } | |
| 2529 | + $r .= "\n\t<tr id=\"csmb-{$key}\" class=\"{$style}\">"; | |
| 2530 | + $r .= "\n\t\t<td class=\"left\"><div><input type=\"text\" name=\"csmb[{$key}][key]\" id=\"csmb[{$key}][key]\" class=\"optname\" size=\"20\" value=\"{$key}\" readonly /></div>"; | |
| 2531 | + $r .= "\n\t\t<div><input type=\"text\" name=\"csmb[{$key}][name]\" id=\"csmb[{$key}][name]\" class=\"optname\" size=\"20\" value=\"{$name}\" /></div>"; | |
| 2532 | + $r .= "\n\t\t<div class=\"optcheck\"><select name=\"csmb[{$key}][means]\" id=\"csmb[{$key}][means]\">" . $meansoption . "</select>\n"; | |
| 2533 | + $r .= "<input type=\"checkbox\" name=\"csmb[{$key}][essential]\" id=\"csmb[{$key}][essential]\" value=\"1\"{$essential} /><label for=\"csmb[{$key}][essential]\">" . esc_html__( 'Required', 'usces' ) . "</label>\n"; | |
| 2534 | + $r .= "<select name=\"csmb[{$key}][position]\" id=\"csmb[{$key}][position]\">" . $positionsoption . '</select></div>'; | |
| 2535 | + $r .= "\n\t\t<div class=\"submit\"><input type=\"button\" class=\"button\" name=\"del_csmb[{$key}]\" id=\"del_csmb[{$key}]\" value=\"" . esc_attr__( 'Delete' ) . "\" onclick=\"customField.delMember('{$key}');\" />"; | |
| 2536 | + $r .= "\n\t\t<input type=\"button\" class=\"button\" name=\"upd_csmb[{$key}]\" id=\"upd_csmb[{$key}]\" value=\"" . esc_attr__( 'Update' ) . "\" onclick=\"customField.updMember('{$key}');\" /></div>"; | |
| 2537 | + $r .= "\n\t\t<div id=\"csmb_loading-{$key}\" class=\"meta_submit_loading\"></div>"; | |
| 2538 | + $r .= '</td>'; | |
| 2539 | + $r .= "\n\t\t<td class=\"item-opt-value\"><textarea name=\"csmb[{$key}][value]\" id=\"csmb[{$key}][value]\" class=\"optvalue\">{$value}</textarea></td>\n\t</tr>"; | |
| 2540 | + return $r; | |
| 2541 | +} | |
| 2542 | + | |
| 2543 | +/** | |
| 2544 | + * List admin custom member meta row | |
| 2545 | + * | |
| 2546 | + * @param string $key Key. | |
| 2547 | + * @param array $entry Entry data. | |
| 2548 | + * @return string | |
| 2549 | + */ | |
| 2550 | +function _list_admin_custom_member_meta_row( $key, $entry ) { | |
| 2551 | + $r = ''; | |
| 2552 | + $style = ''; | |
| 2553 | + $key = esc_attr( $key ); | |
| 2554 | + | |
| 2555 | + $name = esc_attr( $entry['name'] ); | |
| 2556 | + $means = get_option( 'usces_custom_member_select', array() ); | |
| 2557 | + $meansoption = ''; | |
| 2558 | + foreach ( $means as $meankey => $meanvalue ) { | |
| 2559 | + $meansoption .= '<option value="' . esc_attr( $meankey ) . '"' . selected( $meankey, $entry['means'], false ) . '>' . esc_html( $meanvalue ) . "</option>\n"; | |
| 2560 | + } | |
| 2561 | + $essential = ( 1 === (int) $entry['essential'] ) ? ' checked="checked"' : ''; | |
| 2562 | + $value = ''; | |
| 2563 | + if ( is_array( $entry['value'] ) ) { | |
| 2564 | + foreach ( $entry['value'] as $k => $v ) { | |
| 2565 | + $value .= $v . "\n"; | |
| 2566 | + } | |
| 2567 | + } | |
| 2568 | + $value = esc_attr( trim( $value ) ); | |
| 2569 | + $r .= "\n\t<tr id=\"admb-{$key}\" class=\"{$style}\">"; | |
| 2570 | + $r .= "\n\t\t<td class=\"left\"><div><input type=\"text\" name=\"admb[{$key}][key]\" id=\"admb[{$key}][key]\" class=\"optname\" size=\"20\" value=\"{$key}\" readonly /></div>"; | |
| 2571 | + $r .= "\n\t\t<div><input type=\"text\" name=\"admb[{$key}][name]\" id=\"admb[{$key}][name]\" class=\"optname\" size=\"20\" value=\"{$name}\" /></div>"; | |
| 2572 | + $r .= "\n\t\t<div class=\"optcheck\"><select name=\"admb[{$key}][means]\" id=\"admb[{$key}][means]\">" . $meansoption . "</select>\n"; | |
| 2573 | + $r .= "<input type=\"checkbox\" name=\"admb[{$key}][essential]\" id=\"admb[{$key}][essential]\" value=\"1\"{$essential} /><label for=\"admb[{$key}][essential]\">" . esc_html__( 'Required', 'usces' ) . "</label>\n"; | |
| 2574 | + $r .= '</div>'; | |
| 2575 | + $r .= "\n\t\t<div class=\"submit\"><input type=\"button\" class=\"button\" name=\"del_admb[{$key}]\" id=\"del_admb[{$key}]\" value=\"" . esc_attr__( 'Delete' ) . "\" onclick=\"customField.delAdmb('{$key}');\" />"; | |
| 2576 | + $r .= "\n\t\t<input type=\"button\" class=\"button\" name=\"upd_admb[{$key}]\" id=\"upd_admb[{$key}]\" value=\"" . esc_attr__( 'Update' ) . "\" onclick=\"customField.updAdmb('{$key}');\" /></div>"; | |
| 2577 | + $r .= "\n\t\t<div id=\"admb_loading-{$key}\" class=\"meta_submit_loading\"></div>"; | |
| 2578 | + $r .= '</td>'; | |
| 2579 | + $r .= "\n\t\t<td class=\"item-opt-value\"><textarea name=\"admb[{$key}][value]\" id=\"admb[{$key}][value]\" class=\"optvalue\">{$value}</textarea></td>\n\t</tr>"; | |
| 2580 | + return $r; | |
| 2581 | +} | |
| 2582 | + | |
| 2583 | +/** | |
| 2584 | + * Change State/Prefecture | |
| 2585 | + */ | |
| 2586 | +function change_states_ajax() { | |
| 2587 | + global $usces, $usces_states; | |
| 2588 | + | |
| 2589 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 2590 | + | |
| 2591 | + $c = $_POST['country']; | |
| 2592 | + $res = ''; | |
| 2593 | + $prefs = get_usces_states( $c ); | |
| 2594 | + if ( is_array( $prefs ) && 0 < count( $prefs ) ) { | |
| 2595 | + foreach ( (array) $prefs as $state ) { | |
| 2596 | + $res .= '<option value="' . $state . '">' . $state . '</option>'; | |
| 2597 | + } | |
| 2598 | + } else { | |
| 2599 | + die( 'error' ); | |
| 2600 | + } | |
| 2601 | + die( $res ); | |
| 2602 | +} | |
| 2603 | + | |
| 2604 | +/** | |
| 2605 | + * State/Prefecture | |
| 2606 | + * | |
| 2607 | + * @param string $country Country. | |
| 2608 | + * @return array | |
| 2609 | + */ | |
| 2610 | +function get_usces_states( $country ) { | |
| 2611 | + global $usces, $usces_states; | |
| 2612 | + | |
| 2613 | + $states = array(); | |
| 2614 | + $prefs = wel_safe_maybe_unserialize( $usces->options['province'] ); | |
| 2615 | + if ( ! isset( $prefs[ $country ] ) || empty( $prefs[ $country ] ) ) { | |
| 2616 | + if ( $country == $usces->options['system']['base_country'] ) { | |
| 2617 | + foreach ( (array) $prefs as $state ) { | |
| 2618 | + if ( ! is_array( $state ) ) { | |
| 2619 | + array_push( $states, esc_html( $state ) ); | |
| 2620 | + } | |
| 2621 | + } | |
| 2622 | + if ( 0 === count( $states ) ) { | |
| 2623 | + if ( ! empty( $usces_states[ $country ] ) ) { | |
| 2624 | + $prefs = $usces_states[ $country ]; | |
| 2625 | + if ( is_array( $prefs ) ) { | |
| 2626 | + $states = array_map( 'esc_html', $prefs ); | |
| 2627 | + } | |
| 2628 | + } | |
| 2629 | + } | |
| 2630 | + } else { | |
| 2631 | + if ( ! empty( $usces_states[ $country ] ) ) { | |
| 2632 | + $prefs = $usces_states[ $country ]; | |
| 2633 | + if ( is_array( $prefs ) ) { | |
| 2634 | + $states = array_map( 'esc_html', $prefs ); | |
| 2635 | + } | |
| 2636 | + } | |
| 2637 | + } | |
| 2638 | + } else { | |
| 2639 | + $states = is_array( $prefs[ $country ] ) ? array_map( 'esc_html', $prefs[ $country ] ) : esc_html( $prefs[ $country ] ); | |
| 2640 | + } | |
| 2641 | + return $states; | |
| 2642 | +} | |
| 2643 | + | |
| 2644 | +/** | |
| 2645 | + * Target market countries | |
| 2646 | + */ | |
| 2647 | +function target_market_ajax() { | |
| 2648 | + global $usces; | |
| 2649 | + | |
| 2650 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 2651 | + $response = array(); | |
| 2652 | + $target = explode( ',', $_POST['target'] ); | |
| 2653 | + foreach ( (array) $target as $country ) { | |
| 2654 | + $prefs = get_usces_states( $country ); | |
| 2655 | + if ( is_array( $prefs ) && ! empty( $prefs ) ) { | |
| 2656 | + $pos = strpos( $prefs[0], '--' ); | |
| 2657 | + if ( false !== $pos ) { | |
| 2658 | + array_shift( $prefs ); | |
| 2659 | + } | |
| 2660 | + $response[] = $country . ',' . implode( "\n", $prefs ); | |
| 2661 | + } else { | |
| 2662 | + $response[] = $country; | |
| 2663 | + } | |
| 2664 | + } | |
| 2665 | + wp_send_json( $response ); | |
| 2666 | +} | |
| 2667 | + | |
| 2668 | +/** | |
| 2669 | + * Admin ajax | |
| 2670 | + */ | |
| 2671 | +function usces_admin_ajax() { | |
| 2672 | + switch ( $_POST['mode'] ) { | |
| 2673 | + case 'options_backup': | |
| 2674 | + check_admin_referer( 'options_backup', 'wc_nonce' ); | |
| 2675 | + $options = get_option( 'usces' ); | |
| 2676 | + $res = true; | |
| 2677 | + if ( is_array( $options ) ) { | |
| 2678 | + $usces_backup_date = current_time( 'mysql' ); | |
| 2679 | + update_option( 'usces_backup', $options ); | |
| 2680 | + update_option( 'usces_backup_date', $usces_backup_date ); | |
| 2681 | + $res = $usces_backup_date; | |
| 2682 | + } else { | |
| 2683 | + $res = false; | |
| 2684 | + } | |
| 2685 | + die( $res ); | |
| 2686 | + break; | |
| 2687 | + case 'options_restore': | |
| 2688 | + check_admin_referer( 'options_restore', 'wc_nonce' ); | |
| 2689 | + $options = get_option( 'usces_backup' ); | |
| 2690 | + $res = true; | |
| 2691 | + if ( is_array( $options ) ) { | |
| 2692 | + update_option( 'usces', $options ); | |
| 2693 | + } else { | |
| 2694 | + $res = false; | |
| 2695 | + } | |
| 2696 | + die( $res ); | |
| 2697 | + break; | |
| 2698 | + } | |
| 2699 | + do_action( 'usces_action_admin_ajax' ); | |
| 2700 | +} | |
| 2701 | + | |
| 2702 | +/** | |
| 2703 | + * Order amount recalculation | |
| 2704 | + * | |
| 2705 | + * @param int $order_id Order ID. | |
| 2706 | + * @param int $mem_id Member ID. | |
| 2707 | + * @param int $post_id Post ID. | |
| 2708 | + * @param float $price Price. | |
| 2709 | + * @param int $quant Quantity. | |
| 2710 | + * @param array $cart_id Cart ID. | |
| 2711 | + * @param int $use_point Use point. | |
| 2712 | + * @param float $shipping_charge Shipping charge. | |
| 2713 | + * @param float $cod_fee Fee. | |
| 2714 | + * @param float $discount Discount. | |
| 2715 | + * @param string $change_taxrate Change applicable tax rate. | |
| 2716 | + */ | |
| 2717 | +function usces_order_recalculation( $order_id, $mem_id, $post_id, $price, $quant, $cart_id, $use_point, $shipping_charge, $cod_fee, $discount = 0, $change_taxrate = '' ) { | |
| 2718 | + global $usces; | |
| 2719 | + | |
| 2720 | + $data = array(); | |
| 2721 | + $res = 'ok'; | |
| 2722 | + | |
| 2723 | + $cart = array(); | |
| 2724 | + $post_id_count = ( is_array( $post_id ) ) ? count( $post_id ) : 0; | |
| 2725 | + for ( $i = 0; $i < $post_id_count; $i++ ) { | |
| 2726 | + if ( $post_id[ $i ] ) { | |
| 2727 | + $cart[] = array( | |
| 2728 | + 'post_id' => $post_id[ $i ], | |
| 2729 | + 'price' => (float) $price[ $i ], | |
| 2730 | + 'quantity' => (float) $quant[ $i ], | |
| 2731 | + ); | |
| 2732 | + } | |
| 2733 | + } | |
| 2734 | + | |
| 2735 | + if ( 'change' === $change_taxrate ) { | |
| 2736 | + if ( usces_is_reduced_taxrate() ) { | |
| 2737 | + $usces_tax = Welcart_Tax::get_instance(); | |
| 2738 | + $usces_tax->set_order_condition_reduced_taxrate( $order_id ); | |
| 2739 | + for ( $i = 0; $i < $post_id_count; $i++ ) { | |
| 2740 | + if ( $cart_id[ $i ] ) { | |
| 2741 | + $taxrate = usces_get_ordercart_meta( 'taxrate', $cart_id[ $i ] ); | |
| 2742 | + if ( ! $taxrate ) { | |
| 2743 | + $ordercart = usces_get_ordercartdata_row( $cart_id[ $i ] ); | |
| 2744 | + $sku['taxrate'] = $usces_tax->get_sku_applicable_taxrate( $post_id[ $i ], $ordercart['sku_code'] ); | |
| 2745 | + $usces_tax->set_ordercart_applicable_taxrate( $cart_id[ $i ], $sku ); | |
| 2746 | + } | |
| 2747 | + } | |
| 2748 | + } | |
| 2749 | + $data['status'] = $res; | |
| 2750 | + $data['tax_mode'] = 'reduced'; | |
| 2751 | + wp_send_json( $data ); | |
| 2752 | + } | |
| 2753 | + $condition = $usces->get_condition(); | |
| 2754 | + } else { | |
| 2755 | + if ( ! empty( $order_id ) ) { | |
| 2756 | + $condition = usces_get_order_condition( $order_id ); | |
| 2757 | + } else { | |
| 2758 | + $condition = $usces->get_condition(); | |
| 2759 | + } | |
| 2760 | + } | |
| 2761 | + | |
| 2762 | + $tax_display = ( isset( $condition['tax_display'] ) ) ? $condition['tax_display'] : usces_get_tax_display(); | |
| 2763 | + $member_system = ( isset( $condition['membersystem_state'] ) ) ? $condition['membersystem_state'] : $usces->options['membersystem_state']; | |
| 2764 | + $member_system_point = ( isset( $condition['membersystem_point'] ) ) ? $condition['membersystem_point'] : $usces->options['membersystem_point']; | |
| 2765 | + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : usces_get_tax_mode(); | |
| 2766 | + $tax_target = ( isset( $condition['tax_target'] ) ) ? $condition['tax_target'] : usces_get_tax_target(); | |
| 2767 | + $point_coverage = ( isset( $condition['point_coverage'] ) ) ? $condition['point_coverage'] : usces_point_coverage(); | |
| 2768 | + $tax_method = ( isset( $condition['tax_method'] ) ) ? $condition['tax_method'] : $usces->options['tax_method']; | |
| 2769 | + | |
| 2770 | + $total_items_price = 0; | |
| 2771 | + foreach ( $cart as $cart_row ) { | |
| 2772 | + $total_items_price += $cart_row['price'] * $cart_row['quantity']; | |
| 2773 | + } | |
| 2774 | + $meminfo = $usces->get_member_info( $mem_id ); | |
| 2775 | + | |
| 2776 | + if ( empty( $discount ) || 'NaN' == $discount ) { | |
| 2777 | + $discount = 0; | |
| 2778 | + } | |
| 2779 | + if ( 'change' == $change_taxrate ) { | |
| 2780 | + $discount = 0; | |
| 2781 | + if ( isset( $condition['display_mode'] ) && 'Promotionsale' === $condition['display_mode'] ) { | |
| 2782 | + if ( isset( $condition['campaign_privilege'] ) && 'discount' === $condition['campaign_privilege'] ) { | |
| 2783 | + if ( 0 === (int) $condition['campaign_category'] ) { | |
| 2784 | + $discount = (float) sprintf( '%.3f', $total_items_price * (float) $condition['privilege_discount'] / 100 ); | |
| 2785 | + } else { | |
| 2786 | + foreach ( $cart as $cart_row ) { | |
| 2787 | + if ( in_category( (int) $condition['campaign_category'], $cart_row['post_id'] ) ) { | |
| 2788 | + $discount += (float) sprintf( '%.3f', $cart_row['price'] * $cart_row['quantity'] * (float) $condition['privilege_discount'] / 100 ); | |
| 2789 | + } | |
| 2790 | + } | |
| 2791 | + } | |
| 2792 | + } | |
| 2793 | + } | |
| 2794 | + if ( 0 != $discount ) { | |
| 2795 | + $decimal = $usces->get_currency_decimal(); | |
| 2796 | + if ( 0 == $decimal ) { | |
| 2797 | + $discount = ceil( $discount ); | |
| 2798 | + } else { | |
| 2799 | + $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT ); | |
| 2800 | + $discount = ceil( $discount * $decipad ) / $decipad; | |
| 2801 | + } | |
| 2802 | + $discount = $discount * -1; | |
| 2803 | + } | |
| 2804 | + } | |
| 2805 | + $discount = apply_filters( 'usces_filter_order_discount_recalculation', $discount, $cart, $condition, $order_id ); | |
| 2806 | + | |
| 2807 | + $point = 0; | |
| 2808 | + if ( empty( $use_point ) || 'NaN' == $use_point ) { | |
| 2809 | + $use_point = 0; | |
| 2810 | + } | |
| 2811 | + if ( 'activate' === $member_system && 'activate' === $member_system_point && ! empty( $meminfo['ID'] ) ) { | |
| 2812 | + if ( isset( $condition['display_mode'] ) && 'Promotionsale' === $condition['display_mode'] ) { | |
| 2813 | + if ( isset( $condition['campaign_privilege'] ) && 'discount' === $condition['campaign_privilege'] ) { | |
| 2814 | + foreach ( $cart as $cart_row ) { | |
| 2815 | + $cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); | |
| 2816 | + if ( ! in_array( $condition['campaign_category'], $cats ) ) { | |
| 2817 | + $product = wel_get_product( $cart_row['post_id'] ); | |
| 2818 | + $rate = (float) $product['itemPointrate']; | |
| 2819 | + $price = $cart_row['price'] * $cart_row['quantity']; | |
| 2820 | + $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) ); | |
| 2821 | + } | |
| 2822 | + } | |
| 2823 | + } elseif ( isset( $condition['campaign_privilege'] ) && 'point' === $condition['campaign_privilege'] ) { | |
| 2824 | + foreach ( $cart as $cart_row ) { | |
| 2825 | + $product = wel_get_product( $cart_row['post_id'] ); | |
| 2826 | + $rate = (float) $product['itemPointrate']; | |
| 2827 | + $price = $cart_row['price'] * $cart_row['quantity']; | |
| 2828 | + $cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); | |
| 2829 | + if ( in_array( $condition['campaign_category'], $cats ) ) { | |
| 2830 | + $point = sprintf( '%.3f', $point + ( $price * $rate / 100 * (float) $condition['privilege_point'] ) ); | |
| 2831 | + } else { | |
| 2832 | + $point = sprintf( '%.3f', $point + ( $price * $rate / 100 ) ); | |
| 2833 | + } | |
| 2834 | + } | |
| 2835 | + } | |
| 2836 | + } else { | |
| 2837 | + foreach ( $cart as $cart_row ) { | |
| 2838 | + $product = wel_get_product( $cart_row['post_id'] ); | |
| 2839 | + $rate = (float) $product['itemPointrate']; | |
| 2840 | + $price = $cart_row['price'] * $cart_row['quantity']; | |
| 2841 | + $point = sprintf( '%.3f', $point + ( $price * $rate / 100 ) ); | |
| 2842 | + } | |
| 2843 | + } | |
| 2844 | + | |
| 2845 | + if ( 0 < $use_point ) { | |
| 2846 | + $point = (float) sprintf( '%.3f', $point - ( $point * (int) $use_point / $total_items_price ) ); | |
| 2847 | + $point = ceil( $point ); | |
| 2848 | + if ( 0 > $point ) { | |
| 2849 | + $point = 0; | |
| 2850 | + } | |
| 2851 | + } else { | |
| 2852 | + if ( 0 < $point ) { | |
| 2853 | + $point = ceil( $point ); | |
| 2854 | + } | |
| 2855 | + } | |
| 2856 | + } | |
| 2857 | + $point = apply_filters( 'usces_filter_set_point_recalculation', $point, $condition, $cart, $meminfo, $use_point, $order_id ); | |
| 2858 | + | |
| 2859 | + $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee; | |
| 2860 | + if ( $total_price < 0 ) { | |
| 2861 | + $total_price = 0; | |
| 2862 | + } | |
| 2863 | + $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee ); // Deprecated. | |
| 2864 | + $total_price = apply_filters( 'usces_filter_order_total_price_recalculation', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee, $cart, $order_id ); | |
| 2865 | + $materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'condition' ); | |
| 2866 | + if ( 'activate' === $tax_display ) { | |
| 2867 | + if ( 'include' === $tax_mode ) { | |
| 2868 | + $tax = 0; | |
| 2869 | + $include_tax = usces_internal_tax( $materials, 'return' ); | |
| 2870 | + } else { | |
| 2871 | + // $tax = $usces->getTax( $total_price, $materials ); | |
| 2872 | + if ( 1 === (int) $point_coverage ) { | |
| 2873 | + if ( 'products' === $tax_target ) { | |
| 2874 | + $total = (float) $total_items_price + (float) $discount; | |
| 2875 | + } else { | |
| 2876 | + $total = (float) $total_items_price + (float) $discount + (float) $shipping_charge + (float) $cod_fee; | |
| 2877 | + } | |
| 2878 | + } else { | |
| 2879 | + if ( 'products' === $tax_target ) { | |
| 2880 | + $total = (float) $total_items_price + (float) $discount; | |
| 2881 | + } else { | |
| 2882 | + if ( empty( $use_point ) ) { | |
| 2883 | + $use_point = 0; | |
| 2884 | + } | |
| 2885 | + $total = (float) $total_items_price + (float) $discount - (int) $use_point + (float) $shipping_charge + (float) $cod_fee; | |
| 2886 | + } | |
| 2887 | + } | |
| 2888 | + $tax = (float) sprintf( '%.3f', (float) $total * (float) $condition['tax_rate'] / 100 ); | |
| 2889 | + $tax = usces_tax_rounding_off( $tax, $tax_method ); | |
| 2890 | + $include_tax = 0; | |
| 2891 | + } | |
| 2892 | + } else { | |
| 2893 | + $tax = 0; | |
| 2894 | + $include_tax = 0; | |
| 2895 | + } | |
| 2896 | + $total_full_price = $total_price + $tax; | |
| 2897 | + $total_full_price = apply_filters( 'usces_filter_set_cart_fees_total_full_price', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee ); // Deprecated. | |
| 2898 | + $total_full_price = apply_filters( 'usces_filter_order_total_full_price_recalculation', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee, $cart, $order_id ); | |
| 2899 | + | |
| 2900 | + $data['status'] = $res; | |
| 2901 | + $data['tax_mode'] = 'standard'; | |
| 2902 | + $data['discount'] = $discount; | |
| 2903 | + $data['tax'] = usces_crform( $tax, false, false, 'return', false ); | |
| 2904 | + $data['include_tax'] = ( 0 < $include_tax ) ? '(' . usces_crform( $include_tax, false, false, 'return', true ) . ')' : ''; | |
| 2905 | + $data['point'] = $point; | |
| 2906 | + $data['total_full_price'] = usces_crform( $total_full_price, false, false, 'return', false ); | |
| 2907 | + wp_send_json( $data ); | |
| 2908 | +} | |
| 2909 | + | |
| 2910 | +/** | |
| 2911 | + * Order amount recalculation ( for Reduced tax rate ) | |
| 2912 | + * | |
| 2913 | + * @param int $order_id Order ID. | |
| 2914 | + * @param int $mem_id Member ID. | |
| 2915 | + * @param int $post_id Post ID. | |
| 2916 | + * @param float $price Price. | |
| 2917 | + * @param int $quant Quantity. | |
| 2918 | + * @param array $cart_id Cart ID. | |
| 2919 | + * @param int $use_point Use point. | |
| 2920 | + * @param float $shipping_charge Shipping charge. | |
| 2921 | + * @param float $cod_fee Fee. | |
| 2922 | + * @param float $discount_standard Standard tax rate discount. | |
| 2923 | + * @param float $discount_reduced Reduced tax rate discount. | |
| 2924 | + * @param string $change_taxrate Change applicable tax rate. | |
| 2925 | + * @return void | |
| 2926 | + */ | |
| 2927 | +function usces_order_recalculation_reduced( $order_id, $mem_id, $post_id, $price, $quant, $cart_id, $use_point, $shipping_charge, $cod_fee, $discount_standard = 0, $discount_reduced = 0, $change_taxrate = '' ) { | |
| 2928 | + global $usces; | |
| 2929 | + | |
| 2930 | + $usces_tax = Welcart_Tax::get_instance(); | |
| 2931 | + | |
| 2932 | + $data = array(); | |
| 2933 | + $res = 'ok'; | |
| 2934 | + | |
| 2935 | + if ( 'change' === $change_taxrate ) { | |
| 2936 | + $condition = $usces->get_condition(); | |
| 2937 | + $usces_tax->set_order_condition_reduced_taxrate( $order_id ); | |
| 2938 | + } else { | |
| 2939 | + if ( ! empty( $order_id ) ) { | |
| 2940 | + $condition = usces_get_order_condition( $order_id ); | |
| 2941 | + } else { | |
| 2942 | + $condition = $usces->get_condition(); | |
| 2943 | + } | |
| 2944 | + } | |
| 2945 | + | |
| 2946 | + $tax_rate = ( isset( $condition['tax_rate'] ) ) ? (float) $condition['tax_rate'] : (float) $usces->options['tax_rate']; | |
| 2947 | + $tax_rate_reduced = ( isset( $condition['tax_rate_reduced'] ) ) ? (float) $condition['tax_rate_reduced'] : (float) $usces->options['tax_rate_reduced']; | |
| 2948 | + $tax_display = ( isset( $condition['tax_display'] ) ) ? $condition['tax_display'] : usces_get_tax_display(); | |
| 2949 | + $member_system = ( isset( $condition['membersystem_state'] ) ) ? $condition['membersystem_state'] : $usces->options['membersystem_state']; | |
| 2950 | + $member_system_point = ( isset( $condition['membersystem_point'] ) ) ? $condition['membersystem_point'] : $usces->options['membersystem_point']; | |
| 2951 | + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : usces_get_tax_mode(); | |
| 2952 | + $tax_target = ( isset( $condition['tax_target'] ) ) ? $condition['tax_target'] : usces_get_tax_target(); | |
| 2953 | + $point_coverage = ( isset( $condition['point_coverage'] ) ) ? $condition['point_coverage'] : usces_point_coverage(); | |
| 2954 | + $tax_method = ( isset( $condition['tax_method'] ) ) ? $condition['tax_method'] : $usces->options['tax_method']; | |
| 2955 | + | |
| 2956 | + $cart = array(); | |
| 2957 | + $post_id_count = ( is_array( $post_id ) ) ? count( $post_id ) : 0; | |
| 2958 | + for ( $i = 0; $i < $post_id_count; $i++ ) { | |
| 2959 | + if ( $post_id[ $i ] ) { | |
| 2960 | + $ordercart = usces_get_ordercartdata_row( $cart_id[ $i ] ); | |
| 2961 | + $applicable_taxrate = ( 'change' === $change_taxrate ) ? $usces_tax->get_sku_applicable_taxrate( $post_id[ $i ], $ordercart['sku_code'] ) : $usces_tax->get_ordercart_applicable_taxrate( $cart_id[ $i ], $post_id[ $i ], $ordercart['sku_code'] ); | |
| 2962 | + $cart[] = array( | |
| 2963 | + 'post_id' => $post_id[ $i ], | |
| 2964 | + 'sku_code' => $ordercart['sku_code'], | |
| 2965 | + 'price' => (float) $price[ $i ], | |
| 2966 | + 'quantity' => (float) $quant[ $i ], | |
| 2967 | + 'taxrate' => $applicable_taxrate, | |
| 2968 | + ); | |
| 2969 | + } | |
| 2970 | + } | |
| 2971 | + | |
| 2972 | + $subtotal_standard = 0; | |
| 2973 | + $subtotal_reduced = 0; | |
| 2974 | + foreach ( $cart as $cart_row ) { | |
| 2975 | + if ( 'reduced' === $cart_row['taxrate'] ) { | |
| 2976 | + $subtotal_reduced += (float) $cart_row['price'] * (float) $cart_row['quantity']; | |
| 2977 | + } else { | |
| 2978 | + $subtotal_standard += (float) $cart_row['price'] * (float) $cart_row['quantity']; | |
| 2979 | + } | |
| 2980 | + } | |
| 2981 | + $total_items_price = $subtotal_standard + $subtotal_reduced; | |
| 2982 | + $meminfo = $usces->get_member_info( $mem_id ); | |
| 2983 | + | |
| 2984 | + if ( 'change' === $change_taxrate ) { | |
| 2985 | + $discount = 0; | |
| 2986 | + $discount_standard = 0; | |
| 2987 | + $discount_reduced = 0; | |
| 2988 | + if ( isset( $condition['display_mode'] ) && 'Promotionsale' === $condition['display_mode'] ) { | |
| 2989 | + if ( isset( $condition['campaign_privilege'] ) && 'discount' === $condition['campaign_privilege'] ) { | |
| 2990 | + if ( 0 === (int) $condition['campaign_category'] ) { | |
| 2991 | + $discount_standard = (float) sprintf( '%.3f', (float) $subtotal_standard * (float) $condition['privilege_discount'] / 100 ); | |
| 2992 | + $discount_reduced = (float) sprintf( '%.3f', (float) $subtotal_reduced * (float) $condition['privilege_discount'] / 100 ); | |
| 2993 | + } else { | |
| 2994 | + foreach ( $cart as $cart_row ) { | |
| 2995 | + if ( in_category( (int) $condition['campaign_category'], $cart_row['post_id'] ) ) { | |
| 2996 | + $items_discount = (float) sprintf( '%.3f', (float) $cart_row['price'] * (float) $cart_row['quantity'] * (float) $condition['privilege_discount'] / 100 ); | |
| 2997 | + if ( 'reduced' === $cart_row['taxrate'] ) { | |
| 2998 | + $discount_reduced += $items_discount; | |
| 2999 | + } else { | |
| 3000 | + $discount_standard += $items_discount; | |
| 3001 | + } | |
| 3002 | + } | |
| 3003 | + } | |
| 3004 | + } | |
| 3005 | + if ( 0 != $discount_standard || 0 != $discount_reduced ) { | |
| 3006 | + $decimal = $usces->get_currency_decimal(); | |
| 3007 | + if ( 0 == $decimal ) { | |
| 3008 | + $discount_standard = ceil( $discount_standard ); | |
| 3009 | + $discount_reduced = ceil( $discount_reduced ); | |
| 3010 | + } else { | |
| 3011 | + $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT ); | |
| 3012 | + $discount_standard = ceil( $discount_standard * $decipad ) / $decipad; | |
| 3013 | + $discount_reduced = ceil( $discount_reduced * $decipad ) / $decipad; | |
| 3014 | + } | |
| 3015 | + $discount_standard *= -1; | |
| 3016 | + $discount_reduced *= -1; | |
| 3017 | + $discount = $discount_standard + $discount_reduced; | |
| 3018 | + } | |
| 3019 | + } | |
| 3020 | + } | |
| 3021 | + } | |
| 3022 | + $discount = $discount_standard + $discount_reduced; | |
| 3023 | + $discount = apply_filters( 'usces_filter_order_discount_recalculation', $discount, $cart, $condition, $order_id ); | |
| 3024 | + | |
| 3025 | + $point = 0; | |
| 3026 | + if ( empty( $use_point ) || 'NaN' == $use_point ) { | |
| 3027 | + $use_point = 0; | |
| 3028 | + } | |
| 3029 | + if ( 'activate' === $member_system && 'activate' === $member_system_point && ! empty( $meminfo['ID'] ) ) { | |
| 3030 | + if ( isset( $condition['display_mode'] ) && 'Promotionsale' === $condition['display_mode'] ) { | |
| 3031 | + if ( isset( $condition['campaign_privilege'] ) && 'discount' === $condition['campaign_privilege'] ) { | |
| 3032 | + foreach ( $cart as $cart_row ) { | |
| 3033 | + $cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); | |
| 3034 | + if ( ! in_array( $condition['campaign_category'], $cats ) ) { | |
| 3035 | + $product = wel_get_product( $cart_row['post_id'] ); | |
| 3036 | + $rate = (float) $product['itemPointrate']; | |
| 3037 | + $price = $cart_row['price'] * $cart_row['quantity']; | |
| 3038 | + $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) ); | |
| 3039 | + } | |
| 3040 | + } | |
| 3041 | + } elseif ( isset( $condition['campaign_privilege'] ) && 'point' === $condition['campaign_privilege'] ) { | |
| 3042 | + foreach ( $cart as $cart_row ) { | |
| 3043 | + $product = wel_get_product( $cart_row['post_id'] ); | |
| 3044 | + $rate = (float) $product['itemPointrate']; | |
| 3045 | + $price = $cart_row['price'] * $cart_row['quantity']; | |
| 3046 | + $cats = $usces->get_post_term_ids( $cart_row['post_id'], 'category' ); | |
| 3047 | + if ( in_array( $condition['campaign_category'], $cats ) ) { | |
| 3048 | + $point = sprintf( '%.3f', $point + ( $price * $rate / 100 * (float) $condition['privilege_point'] ) ); | |
| 3049 | + } else { | |
| 3050 | + $point = sprintf( '%.3f', $point + ( $price * $rate / 100 ) ); | |
| 3051 | + } | |
| 3052 | + } | |
| 3053 | + } | |
| 3054 | + } else { | |
| 3055 | + foreach ( $cart as $cart_row ) { | |
| 3056 | + $product = wel_get_product( $cart_row['post_id'] ); | |
| 3057 | + $rate = (float) $product['itemPointrate']; | |
| 3058 | + $price = $cart_row['price'] * $cart_row['quantity']; | |
| 3059 | + $point = sprintf( '%.3f', $point + ( $price * $rate / 100 ) ); | |
| 3060 | + } | |
| 3061 | + } | |
| 3062 | + | |
| 3063 | + if ( 0 < $use_point ) { | |
| 3064 | + $point = (float) sprintf( '%.3f', $point - ( $point * (int) $use_point / $total_items_price ) ); | |
| 3065 | + $point = ceil( $point ); | |
| 3066 | + if ( 0 > $point ) { | |
| 3067 | + $point = 0; | |
| 3068 | + } | |
| 3069 | + } else { | |
| 3070 | + if ( 0 < $point ) { | |
| 3071 | + $point = ceil( $point ); | |
| 3072 | + } | |
| 3073 | + } | |
| 3074 | + } | |
| 3075 | + $point = apply_filters( 'usces_filter_set_point_recalculation', $point, $condition, $cart, $meminfo, $use_point, $order_id ); | |
| 3076 | + | |
| 3077 | + $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee; | |
| 3078 | + if ( $total_price < 0 ) { | |
| 3079 | + $total_price = 0; | |
| 3080 | + } | |
| 3081 | + $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee ); // Deprecated. | |
| 3082 | + $total_price = apply_filters( 'usces_filter_order_total_price_recalculation', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee, $cart, $order_id ); | |
| 3083 | + | |
| 3084 | + $tax = 0; | |
| 3085 | + $tax_standard = 0; | |
| 3086 | + $tax_reduced = 0; | |
| 3087 | + $include_tax = 0; | |
| 3088 | + if ( 'activate' === $tax_display ) { | |
| 3089 | + if ( 'all' === $tax_target ) { | |
| 3090 | + if ( 0 < $shipping_charge ) { | |
| 3091 | + $subtotal_standard += (float) $shipping_charge; | |
| 3092 | + } | |
| 3093 | + if ( 0 < $cod_fee ) { | |
| 3094 | + $subtotal_standard += (float) $cod_fee; | |
| 3095 | + } | |
| 3096 | + } | |
| 3097 | + | |
| 3098 | + if ( 'include' === $tax_mode ) { | |
| 3099 | + if ( 0 < $subtotal_standard ) { | |
| 3100 | + $tax_standard = (float) sprintf( '%.3f', ( (float) $subtotal_standard + (float) $discount_standard ) * $tax_rate / ( 100 + $tax_rate ) ); | |
| 3101 | + } | |
| 3102 | + if ( 0 < $subtotal_reduced ) { | |
| 3103 | + $tax_reduced = (float) sprintf( '%.3f', ( (float) $subtotal_reduced + (float) $discount_reduced ) * $tax_rate_reduced / ( 100 + $tax_rate_reduced ) ); | |
| 3104 | + } | |
| 3105 | + } else { | |
| 3106 | + if ( 0 < $subtotal_standard ) { | |
| 3107 | + $tax_standard = (float) sprintf( '%.3f', ( (float) $subtotal_standard + (float) $discount_standard ) * $tax_rate / 100 ); | |
| 3108 | + } | |
| 3109 | + if ( 0 < $subtotal_reduced ) { | |
| 3110 | + $tax_reduced = (float) sprintf( '%.3f', ( (float) $subtotal_reduced + (float) $discount_reduced ) * $tax_rate_reduced / 100 ); | |
| 3111 | + } | |
| 3112 | + } | |
| 3113 | + | |
| 3114 | + $tax_standard = usces_tax_rounding_off( $tax_standard, $tax_method ); | |
| 3115 | + $tax_reduced = usces_tax_rounding_off( $tax_reduced, $tax_method ); | |
| 3116 | + | |
| 3117 | + $materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'cart' ); | |
| 3118 | + if ( 'include' === $tax_mode ) { | |
| 3119 | + $include_tax = $tax_standard + $tax_reduced; | |
| 3120 | + $total_full_price = $total_price; | |
| 3121 | + } else { | |
| 3122 | + $tax = apply_filters( 'usces_filter_order_tax_recalculation', $tax_standard + $tax_reduced, $materials ); | |
| 3123 | + $total_full_price = $total_price + $tax; | |
| 3124 | + } | |
| 3125 | + } else { | |
| 3126 | + $total_full_price = $total_price; | |
| 3127 | + } | |
| 3128 | + $total_full_price = apply_filters( 'usces_filter_set_cart_fees_total_full_price', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee ); // Deprecated. | |
| 3129 | + $total_full_price = apply_filters( 'usces_filter_order_total_full_price_recalculation', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee, $cart, $order_id ); | |
| 3130 | + | |
| 3131 | + $data['status'] = $res; | |
| 3132 | + $data['tax_mode'] = 'reduced'; | |
| 3133 | + $data['discount'] = $discount; | |
| 3134 | + $data['tax'] = $tax; | |
| 3135 | + $data['point'] = $point; | |
| 3136 | + $data['total_full_price'] = $total_full_price; | |
| 3137 | + $data['subtotal_standard'] = $subtotal_standard; | |
| 3138 | + $data['subtotal_reduced'] = $subtotal_reduced; | |
| 3139 | + //if ( 'change' == $change_taxrate ) { | |
| 3140 | + $data['discount_standard'] = $discount_standard; | |
| 3141 | + $data['discount_reduced'] = $discount_reduced; | |
| 3142 | + //} | |
| 3143 | + $data['tax_standard'] = $tax_standard; | |
| 3144 | + $data['tax_reduced'] = $tax_reduced; | |
| 3145 | + $data['include_tax'] = $include_tax; | |
| 3146 | + wp_send_json( $data ); | |
| 3147 | +} | |
| 3148 | + | |
| 3149 | +/** | |
| 3150 | + * Application of reduced tax rate | |
| 3151 | + * | |
| 3152 | + * @param array $sku SKU data. | |
| 3153 | + * @return void | |
| 3154 | + */ | |
| 3155 | +function usces_sku_meta_row_reduced_taxrate( $sku ) { | |
| 3156 | + global $usces; | |
| 3157 | + | |
| 3158 | + if ( $usces->is_reduced_taxrate() ) : | |
| 3159 | + $standard = $usces->options['tax_rate']; | |
| 3160 | + $reduced = $usces->options['tax_rate_reduced']; | |
| 3161 | + $taxrate = ( isset( $sku['taxrate'] ) ) ? $sku['taxrate'] : ''; | |
| 3162 | + ?> | |
| 3163 | + <select id="itemsku[<?php echo esc_attr( $sku['meta_id'] ); ?>][applicable_taxrate]" name="itemsku[<?php echo esc_attr( $sku['meta_id'] ); ?>][applicable_taxrate]" class="sku_applicable_taxrate" > | |
| 3164 | + <option value="standard"<?php selected( $taxrate, 'reduced' ); ?>><?php esc_html_e( 'Standard tax rate', 'usces' ); ?>(<?php echo esc_html( $standard ); ?>%)</option> | |
| 3165 | + <option value="reduced"<?php selected( $taxrate, 'reduced' ); ?>><?php esc_html_e( 'Reduced tax rate', 'usces' ); ?>(<?php echo esc_html( $reduced ); ?>%)</option> | |
| 3166 | + </select> | |
| 3167 | + <?php | |
| 3168 | + endif; | |
| 3169 | +} | |
| 3170 | + | |
| 3171 | +/** | |
| 3172 | + * Application of reduced tax rate | |
| 3173 | + */ | |
| 3174 | +function usces_newsku_meta_row_reduced_taxrate() { | |
| 3175 | + global $usces; | |
| 3176 | + | |
| 3177 | + if ( $usces->is_reduced_taxrate() ) : | |
| 3178 | + $standard = $usces->options['tax_rate']; | |
| 3179 | + $reduced = $usces->options['tax_rate_reduced']; | |
| 3180 | + ?> | |
| 3181 | + <select id="newsku_applicable_taxrate" name="newsku_applicable_taxrate" class="newsku_applicable_taxrate" > | |
| 3182 | + <option value="standard"><?php esc_html_e( 'Standard tax rate', 'usces' ); ?>(<?php echo esc_html( $standard ); ?>%)</option> | |
| 3183 | + <option value="reduced"><?php esc_html_e( 'Reduced tax rate', 'usces' ); ?>(<?php echo esc_html( $reduced ); ?>%)</option> | |
| 3184 | + </select> | |
| 3185 | + <?php | |
| 3186 | + endif; | |
| 3187 | +} | |
| 3188 | + | |
| 3189 | +/** | |
| 3190 | + * When deleting product data from the trash bin, also delete "_item", "_sku", and "_opt". | |
| 3191 | + * | |
| 3192 | + * @param int $post_id Post ID. | |
| 3193 | + */ | |
| 3194 | +function usces_delete_all_item_data( $post_id ) { | |
| 3195 | + $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_SPECIAL_CHARS ); | |
| 3196 | + | |
| 3197 | + if ( ! empty( $action ) && 'delete' === $action && usces_is_item( $post_id ) ) { | |
| 3198 | + wel_delete_all_sku_data( $post_id ); | |
| 3199 | + wel_delete_all_opt_data( $post_id ); | |
| 3200 | + wel_delete_item_data( $post_id ); | |
| 3201 | + } | |
| 3202 | +} | |