WC_Compare_Categories_Class

WooCommerce Compare Categories.

Defined (1)

The class is defined in the following location(s).

/admin/classes/class-wc-compare-categories.php  
  1. class WC_Compare_Categories_Class 
  2.  
  3. public static function init_categories_actions() { 
  4. global $wpdb; 
  5. $cat_msg = ''; 
  6. if(isset($_REQUEST['bt_save_cat'])) { 
  7. $category_name = trim(strip_tags(addslashes($_REQUEST['category_name']))); 
  8. if(isset($_REQUEST['category_id']) && $_REQUEST['category_id'] > 0) { 
  9. $old_data = WC_Compare_Categories_Data::get_row($_REQUEST['category_id']); 
  10. $count_category_name = WC_Compare_Categories_Data::get_count("category_name = '".$category_name."' AND id != '".$_REQUEST['category_id']."'"); 
  11. if ($category_name != '' && $count_category_name == 0) { 
  12. $result = WC_Compare_Categories_Data::update_row($_REQUEST); 
  13. $wpdb->query('UPDATE '.$wpdb->prefix.'postmeta SET meta_value="'.$category_name.'" WHERE meta_value="'.$old_data->category_name.'" AND meta_key="_wpsc_compare_category_name" '); 
  14. $cat_msg = '<div class="updated below-h2" id="result_msg"><p>'.__('Compare Category Successfully edited', 'woocommerce-compare-products' ).'.</p></div>'; 
  15. }else { 
  16. $cat_msg = '<div class="error below-h2" id="result_msg"><p>'.__('Nothing edited! You already have a Compare Category with that name. Use unique names to edit each Compare Category.', 'woocommerce-compare-products' ).'</p></div>'; 
  17. }else{ 
  18. $count_category_name = WC_Compare_Categories_Data::get_count("category_name = '".$category_name."'"); 
  19. if ($category_name != '' && $count_category_name == 0) { 
  20. $category_id = WC_Compare_Categories_Data::insert_row($_REQUEST); 
  21. if ($category_id > 0) { 
  22. $cat_msg = '<div class="updated below-h2" id="result_msg"><p>'.__('Compare Category Successfully created', 'woocommerce-compare-products' ).'.</p></div>'; 
  23. }else { 
  24. $cat_msg = '<div class="error below-h2" id="result_msg"><p>'.__('Compare Category Error created', 'woocommerce-compare-products' ).'.</p></div>'; 
  25. }else { 
  26. $cat_msg = '<div class="error below-h2" id="result_msg"><p>'.__('Nothing created! You already have a Compare Category with that name. Use unique names to create each Compare Category.', 'woocommerce-compare-products' ).'</p></div>'; 
  27.  
  28. if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-delete') { 
  29. $category_id = trim($_REQUEST['category_id']); 
  30. WC_Compare_Categories_Data::delete_row($category_id); 
  31. WC_Compare_Categories_Fields_Data::delete_row("cat_id='".$category_id."'"); 
  32. $cat_msg = '<div class="updated below-h2" id="result_msg"><p>'.__('Compare Category deleted', 'woocommerce-compare-products' ).'.</p></div>'; 
  33. return $cat_msg; 
  34.  
  35. public static function woocp_categories_manager() { 
  36. global $wpdb; 
  37. ?> 
  38.  
  39. <h3><?php if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-edit') { _e('Edit Compare Product Categories', 'woocommerce-compare-products' );}else { _e('Add Compare Product Categories', 'woocommerce-compare-products' ); } ?></h3> 
  40. <?php if(isset($_REQUEST['act']) && $_REQUEST['act'] != 'cat-edit') {?><p><?php _e('Create Categories based on groups of products that share the same compare feature list.', 'woocommerce-compare-products' ); ?></p><?php } ?> 
  41. <form action="admin.php?page=woo-compare-features" method="post" name="form_add_compare" id="form_add_compare"> 
  42. <?php 
  43. if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-edit') { 
  44. $category_id = $_REQUEST['category_id']; 
  45. $cat_data = WC_Compare_Categories_Data::get_row($category_id); 
  46. ?> 
  47. <input type="hidden" value="<?php echo $category_id; ?>" name="category_id" id="category_id" /> 
  48. <?php  
  49. ?> 
  50. <table class="form-table"> 
  51. <tbody> 
  52. <tr valign="top"> 
  53. <th class="titledesc" scope="rpw"><label for="category_name"><?php if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-edit') { _e('Edit Category Name', 'woocommerce-compare-products' ); } else { _e('Category Name', 'woocommerce-compare-products' ); } ?></label></th> 
  54. <td class="forminp"><input type="text" name="category_name" id="category_name" value="<?php if (!empty($cat_data)) { echo stripslashes($cat_data->category_name); } ?>" style="min-width:300px" /></td> 
  55. </tr> 
  56. </tbody> 
  57. </table> 
  58. <p class="submit"> 
  59. <input type="submit" name="bt_save_cat" id="bt_save_cat" class="button button-primary" value="<?php if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-edit') { _e('Save', 'woocommerce-compare-products' ); }else { _e('Create', 'woocommerce-compare-products' ); } ?>" /> <?php if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-edit') { ?><input type="button" class="button" onclick="window.location='admin.php?page=woo-compare-features'" value="<?php _e('Cancel', 'woocommerce-compare-products' ); ?>" /><?php } ?> 
  60. </p> 
  61. </form> 
  62. <?php 
  63.  
  64. public static function woocp_update_cat_orders() { 
  65. check_ajax_referer( 'woocp-update-cat-order', 'security' ); 
  66. $updateRecordsArray = $_REQUEST['recordsArray']; 
  67.  
  68. $listingCounter = 1; 
  69. foreach ($updateRecordsArray as $recordIDValue) { 
  70. WC_Compare_Categories_Data::update_order($recordIDValue, $listingCounter); 
  71. $listingCounter++; 
  72.  
  73. _e('You just save the order for compare categories.', 'woocommerce-compare-products' ); 
  74. die(); 
  75.