VTMIN_Rule_delete

The VarkTech Minimum Purchase for WooCommerce VTMIN Rule delete class.

Defined (1)

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

/admin/vtmin-rules-delete.php  
  1. class VTMIN_Rule_delete { 
  2.  
  3. public function __construct() { 
  4.  
  5.  
  6. public function vtmin_delete_rule () { 
  7. global $post, $vtmin_info, $vtmin_rules_set, $vtmin_rule; 
  8. $post_id = $post->ID;  
  9. $vtmin_rules_set = get_option( 'vtmin_rules_set' ) ; 
  10. $sizeof_rules_set = sizeof($vtmin_rules_set); 
  11. for($i=0; $i < $sizeof_rules_set; $i++) {  
  12. if ($vtmin_rules_set[$i]->post_id == $post_id) { 
  13. unset ($vtmin_rules_set[$i]); //this is the 'delete' 
  14. $i = $sizeof_rules_set;  
  15.  
  16. if (count($vtmin_rules_set) == 0) { 
  17. delete_option( 'vtmin_rules_set' ); 
  18. } else { 
  19. update_option( 'vtmin_rules_set', $vtmin_rules_set ); 
  20. }  
  21.  
  22. /** Change rule status to 'pending' 
  23. if status is 'pending', the rule will not be executed during cart processing  
  24. */  
  25. public function vtmin_trash_rule () { 
  26. global $post, $vtmin_info, $vtmin_rules_set, $vtmin_rule; 
  27. $post_id = $post->ID;  
  28. $vtmin_rules_set = get_option( 'vtmin_rules_set' ) ; 
  29. $sizeof_rules_set = sizeof($vtmin_rules_set); 
  30. for($i=0; $i < $sizeof_rules_set; $i++) {  
  31. if ($vtmin_rules_set[$i]->post_id == $post_id) { 
  32. if ( $vtmin_rules_set[$i]->rule_status = 'publish' ) { //only update if necessary, may already be pending 
  33. $vtmin_rules_set[$i]->rule_status = 'pending'; 
  34. update_option( 'vtmin_rules_set', $vtmin_rules_set );  
  35. $i = $sizeof_rules_set; //set to done 
  36. }  
  37.  
  38. /** Change rule status to 'publish'  
  39. if status is 'pending', the rule will not be executed during cart processing  
  40. */ 
  41. public function vtmin_untrash_rule () { 
  42. global $post, $vtmin_info, $vtmin_rules_set, $vtmin_rule; 
  43. $post_id = $post->ID;  
  44. $vtmin_rules_set = get_option( 'vtmin_rules_set' ) ; 
  45. $sizeof_rules_set = sizeof($vtmin_rules_set); 
  46. for($i=0; $i < $sizeof_rules_set; $i++) {  
  47. if ($vtmin_rules_set[$i]->post_id == $post_id) { 
  48. if ( sizeof($vtmin_rules_set[$i]->rule_error_message) > 0 ) { //if there are error message, the status remains at pending 
  49. //$vtmin_rules_set[$i]->rule_status = 'pending'; status already pending 
  50. global $wpdb; 
  51. $wpdb->update( $wpdb->posts, array( 'post_status' => 'pending' ), array( 'ID' => $post_id ) ); //match the post status to pending, as errors exist. 
  52. } else { 
  53. $vtmin_rules_set[$i]->rule_status = 'publish'; 
  54. update_option( 'vtmin_rules_set', $vtmin_rules_set );  
  55. $i = $sizeof_rules_set; //set to done 
  56. }  
  57.  
  58.  
  59. public function vtmin_nuke_all_rules() { 
  60. global $post, $vtmin_info; 
  61.  
  62. //DELETE all posts from CPT 
  63. $myPosts = get_posts( array( 'post_type' => 'vtmin-rule', 'number' => 500, 'post_status' => array ('draft', 'publish', 'pending', 'future', 'private', 'trash' ) ) ); 
  64. //$mycustomposts = get_pages( array( 'post_type' => 'vtmin-rule', 'number' => 500) ); 
  65. foreach( $myPosts as $mypost ) { 
  66. // Delete's each post. 
  67. wp_delete_post( $mypost->ID, true); 
  68. // Set to False if you want to send them to Trash. 
  69.  
  70. //DELETE matching option array 
  71. delete_option( 'vtmin_rules_set' ); 
  72. }  
  73.  
  74. public function vtmin_nuke_all_rule_cats() { 
  75. global $vtmin_info; 
  76.  
  77. //DELETE all rule category entries 
  78. $terms = get_terms($vtmin_info['rulecat_taxonomy'], 'hide_empty=0&parent=0' ); 
  79. $count = count($terms); 
  80. if ( $count > 0 ) {  
  81. foreach ( $terms as $term ) { 
  82. wp_delete_term( $term->term_id, $vtmin_info['rulecat_taxonomy'] ); 
  83. }  
  84. }  
  85.  
  86. public function vtmin_repair_all_rules() { 
  87. global $wpdb, $post, $vtmin_info, $vtmin_rules_set, $vtmin_rule;  
  88. $vtmin_rules_set = get_option( 'vtmin_rules_set' ) ; 
  89. $sizeof_rules_set = sizeof($vtmin_rules_set); 
  90. for($i=0; $i < $sizeof_rules_set; $i++) {  
  91. $test_post = get_post($vtmin_rules_set[$i]->post_id ); 
  92. if ( !$test_post ) { 
  93. unset ($vtmin_rules_set[$i]); //this is the 'delete' 
  94. }  
  95.  
  96. if (count($vtmin_rules_set) == 0) { 
  97. delete_option( 'vtmin_rules_set' ); 
  98. } else { 
  99. update_option( 'vtmin_rules_set', $vtmin_rules_set ); 
  100. }  
  101.  
  102. } //end class