public function save_quantity_rule_meta($post_id)
 {
     // Validate Post Type
     if (!isset($_POST['post_type']) or $_POST['post_type'] !== 'quantity-rule') {
         return;
     }
     // Validate User
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     // Verify Nonce
     if (!isset($_POST["_wpbo_rule_value_nonce"]) or !wp_verify_nonce($_POST["_wpbo_rule_value_nonce"], plugin_basename(__FILE__))) {
         return;
     }
     // Remove the rule/role transient
     global $wp_roles;
     $roles = $wp_roles->get_names();
     foreach ($roles as $slug => $name) {
         delete_transient('ipq_rules_' . $slug);
     }
     //Also delete the guest transient, which is not a role
     delete_transient('ipq_rules_guest');
     // Make sure $min >= step
     if (isset($_POST['min'])) {
         $min = $_POST['min'];
     }
     // Update Step
     if (isset($_POST['step']) and isset($min)) {
         if ($min < $_POST['step'] && $min > 0) {
             $min = $_POST['step'];
         }
     }
     // Get Min Out of Stock
     if (isset($_POST['min_oos'])) {
         $min_oos = $_POST['min_oos'];
         update_post_meta($post_id, '_min_oos', stripslashes($min_oos));
     }
     // Update Min
     if (isset($min)) {
         update_post_meta($post_id, '_min', stripslashes($min));
     }
     // Update Max
     if (isset($_POST['max'])) {
         $max = $_POST['max'];
         // Validate Max is not less then Min
         if (isset($min) and $max < $min and $max != 0) {
             $max = $min;
         }
         update_post_meta($post_id, '_max', wcqu_validate_number($max));
     }
     // Update Max OOS
     if (isset($_POST['max_oos'])) {
         $max_oos = $_POST['max_oos'];
         // Max must be bigger then min
         if ($max_oos != '' and isset($min_oos) and $min_oos != 0) {
             if ($min_oos > $max_oos) {
                 $max_oos = $min_oos;
             }
         } elseif ($max_oos != '' and isset($min) and $min != 0) {
             if ($min > $max_oos) {
                 $max_oos = $min;
             }
         }
         update_post_meta($post_id, '_max_oos', wcqu_validate_number($max_oos));
     }
     // Update Step
     if (isset($_POST['step'])) {
         update_post_meta($post_id, '_step', wcqu_validate_number($_POST['step']));
     }
     // Update Priority
     if (isset($_POST['priority'])) {
         update_post_meta($post_id, '_priority', wcqu_validate_number($_POST['priority']));
     }
 }
 public function save_quantity_meta_data($post_id)
 {
     // Validate Post Type
     if (!isset($_POST['post_type']) or $_POST['post_type'] !== 'product') {
         return;
     }
     // Validate User
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     // Verify Nonce
     if (!isset($_POST["_wpbo_product_rule_nonce"]) or !wp_verify_nonce($_POST["_wpbo_product_rule_nonce"], plugin_basename(__FILE__))) {
         return;
     }
     // Update Rule Meta Values
     if (isset($_POST['_wpbo_deactive'])) {
         update_post_meta($post_id, '_wpbo_deactive', strip_tags($_POST['_wpbo_deactive']));
     } else {
         update_post_meta($post_id, '_wpbo_deactive', '');
     }
     if (isset($_POST['_wpbo_override'])) {
         update_post_meta($post_id, '_wpbo_override', strip_tags($_POST['_wpbo_override']));
     } else {
         update_post_meta($post_id, '_wpbo_override', '');
     }
     if (isset($_POST['_wpbo_minimum'])) {
         $min = $_POST['_wpbo_minimum'];
     }
     if (isset($_POST['_wpbo_step'])) {
         $step = $_POST['_wpbo_step'];
     }
     /* Make sure min >= step */
     /*
     if ( isset( $step ) and isset( $min ) ) {
     	if ( $min < $step ) {
     		$min = $step;
     	}
     }
     */
     if (isset($_POST['_wpbo_step'])) {
         update_post_meta($post_id, '_wpbo_step', strip_tags(wcqu_validate_number($_POST['_wpbo_step'])));
     }
     if (isset($_POST['_wpbo_minimum'])) {
         if ($min != 0) {
             $min = wcqu_validate_number($min);
         }
         update_post_meta($post_id, '_wpbo_minimum', strip_tags($min));
     }
     /* Make sure Max > Min */
     if (isset($_POST['_wpbo_maximum'])) {
         $max = $_POST['_wpbo_maximum'];
         if (isset($min) and $max < $min and $max != 0) {
             $max = $min;
         }
         update_post_meta($post_id, '_wpbo_maximum', strip_tags(wcqu_validate_number($max)));
     }
     // Update Out of Stock Minimum
     if (isset($_POST['_wpbo_minimum_oos'])) {
         $min_oos = stripslashes($_POST['_wpbo_minimum_oos']);
         if ($min_oos != 0) {
             $min_oos = wcqu_validate_number($min_oos);
         }
         update_post_meta($post_id, '_wpbo_minimum_oos', strip_tags($min_oos));
     }
     // Update Out of Stock Maximum
     if (isset($_POST['_wpbo_maximum_oos'])) {
         $max_oos = stripslashes($_POST['_wpbo_maximum_oos']);
         // Allow the value to be unset
         if ($max_oos != '') {
             // Validate the number
             if ($max_oos != 0) {
                 $max_oos = wcqu_validate_number($max_oos);
             }
             // Max must be bigger then min
             if (isset($min_oos) and $min_oos != 0) {
                 if ($min_oos > $max_oos) {
                     $max_oos = $min_oos;
                 }
             } elseif (isset($min) and $min != 0) {
                 if ($min > $max_oos) {
                     $max_oos = $min;
                 }
             }
         }
         update_post_meta($post_id, '_wpbo_maximum_oos', strip_tags($max_oos));
     }
 }
 public function save_settings()
 {
     // Get Settings
     $settings = get_option('ipq_options');
     // Minimum Product Notification
     if (isset($_POST['ipq_show_qty_note']) and $_POST['ipq_show_qty_note'] == 'on') {
         $settings['ipq_show_qty_note'] = 'on';
     } else {
         $settings['ipq_show_qty_note'] = '';
     }
     // Minimum Note Text
     if (isset($_POST['ipq_qty_text']) and $_POST['ipq_qty_text'] != '') {
         $settings['ipq_qty_text'] = stripslashes($_POST['ipq_qty_text']);
     } else {
         $settings['ipq_qty_text'] = '';
     }
     // Minimum Note Position
     if (isset($_POST['ipq_show_qty_note_pos']) and $_POST['ipq_show_qty_note_pos'] == 'below') {
         $settings['ipq_show_qty_note_pos'] = 'below';
     } else {
         $settings['ipq_show_qty_note_pos'] = 'above';
     }
     // Minimum Note Class
     if (isset($_POST['ipq_qty_class'])) {
         $settings['ipq_qty_class'] = stripslashes($_POST['ipq_qty_class']);
     }
     // Active Rule
     if (isset($_POST['ipq_site_rule_active']) and $_POST['ipq_site_rule_active'] == 'on') {
         $settings['ipq_site_rule_active'] = 'on';
     } else {
         $settings['ipq_site_rule_active'] = '';
     }
     if (isset($_POST['ipq_site_min'])) {
         $min = wcqu_validate_number($_POST['ipq_site_min']);
     }
     if (isset($_POST['ipq_site_step'])) {
         $step = wcqu_validate_number($_POST['ipq_site_step']);
     }
     if (isset($_POST['ipq_site_max'])) {
         $max = wcqu_validate_number($_POST['ipq_site_max']);
     }
     if (isset($_POST['ipq_site_min_oos'])) {
         $min_oos = wcqu_validate_number($_POST['ipq_site_min_oos']);
     }
     if (isset($_POST['ipq_site_max_oos'])) {
         $max_oos = wcqu_validate_number($_POST['ipq_site_max_oos']);
     }
     // Make sure min >= step
     if (isset($step) and isset($min)) {
         if ($min < $step) {
             $min = $step;
         }
     }
     // Make sure min <= max
     if (isset($step) and isset($max)) {
         if ($min > $max and $max != '' and $max != 0) {
             $max = $min;
         }
     }
     // Make sure min_oos <= max and max_oos
     if (isset($min_oos) and $min_oos != 0) {
         if (isset($max_oos) and $max_oos != 0 and $min_oos > $max_oos) {
             $max_oos = $min_oos;
         } else {
             if (!isset($max_oos) and isset($max) and $max != 0 and $min_oos > $max) {
                 $min_oos = $max;
             }
         }
     }
     // Site Minimum
     if (isset($_POST['ipq_site_min'])) {
         $settings['ipq_site_min'] = strip_tags($min);
     }
     // Site Step
     if (isset($_POST['ipq_site_step'])) {
         $settings['ipq_site_step'] = strip_tags($step);
     }
     // Site Max
     if (isset($_POST['ipq_site_max'])) {
         $settings['ipq_site_max'] = strip_tags($max);
     }
     // Site Min OOS
     if (isset($_POST['ipq_site_min_oos'])) {
         $settings['ipq_site_min_oos'] = strip_tags($min_oos);
     }
     // Site Max
     if (isset($_POST['ipq_site_max_oos'])) {
         $settings['ipq_site_max_oos'] = strip_tags($max_oos);
     }
     // Update Settings
     $updated = update_option('ipq_options', $settings);
 }