diff --git a/assets/css/admin-styles.css b/assets/css/admin-styles.css index d1b603f..d0cf708 100755 --- a/assets/css/admin-styles.css +++ b/assets/css/admin-styles.css @@ -137,7 +137,7 @@ span.wpbo_product_values { } /* --------- wpbo company notice ---------- */ -#wpbo-company-notice .inside { +#wpqu-company-notice .inside { text-align: center; } diff --git a/assets/img/rapid-order-logo.png b/assets/img/rapid-order-logo.png new file mode 100644 index 0000000..1f5d3b0 Binary files /dev/null and b/assets/img/rapid-order-logo.png differ diff --git a/assets/img/wpbo-logo.png b/assets/img/wpbo-logo.png deleted file mode 100755 index b773aba..0000000 Binary files a/assets/img/wpbo-logo.png and /dev/null differ diff --git a/assets/js/ipq_input_value_validation.js b/assets/js/ipq_input_value_validation.js index 785adf9..31bcd19 100755 --- a/assets/js/ipq_input_value_validation.js +++ b/assets/js/ipq_input_value_validation.js @@ -62,7 +62,7 @@ jQuery(document).ready( function($) { new_qty = +new_qty + (+step - +rem); // Max Value Validation - if ( +new_qty > +max ) { + if ( max > 0 && +new_qty > +max ) { new_qty = +new_qty - +step; } } diff --git a/includes/class-wcqu-filters.php b/includes/class-wcqu-filters.php index 4f8dff3..00d237a 100755 --- a/includes/class-wcqu-filters.php +++ b/includes/class-wcqu-filters.php @@ -77,7 +77,6 @@ public function input_min_value( $default, $product ) { // Get Value from Rule $min = wcqu_get_value_from_rule( 'min', $product, $rule ); - // Return Value if ( $min == '' or $min == null or (isset($min['min']) and $min['min'] == "")) { return $default; diff --git a/includes/class-wcqu-post-type.php b/includes/class-wcqu-post-type.php index 2f75269..5156680 100755 --- a/includes/class-wcqu-post-type.php +++ b/includes/class-wcqu-post-type.php @@ -1,20 +1,20 @@ - __('Quantity Rules','qau'), 'singular_name' => __('Quantity Rule','qau'), @@ -49,7 +49,7 @@ public function quantity_rule_init() { 'parent_item_colon' => '', 'menu_name' => __('Quantity Rules','qau'), ); - + $args = array( 'labels' => $labels, 'public' => false, @@ -65,21 +65,21 @@ public function quantity_rule_init() { 'supports' => array( 'title' ), 'taxonomies' => array(), ); - + register_post_type( 'quantity-rule', $args ); } - + /* * Register Custom Columns for List View - */ + */ public function quantity_rule_columns( $column ) { - + unset( $column['date'] ); - + $new_columns['priority'] = __('Priority'); $new_columns['min'] = __('Minimum'); $new_columns['max'] = __('Maximum'); - $new_columns['step'] = __('Step Value'); + $new_columns['step'] = __('Step Value'); $new_columns['cats'] = __('Categories'); $new_columns['product_tags'] = __('Tags'); $new_columns['roles'] = __('Roles'); @@ -87,101 +87,101 @@ public function quantity_rule_columns( $column ) { return array_merge( $column, $new_columns ); } - + /* * Get Custom Columns Values for List View - */ + */ public function manage_quantity_rule_columns($column_name, $id) { - + switch ($column_name) { - + case 'priority': echo get_post_meta( $id, '_priority', true ); break; - + case 'min': echo get_post_meta( $id, '_min', true ); break; - + case 'max': echo get_post_meta( $id, '_max', true ); break; - + case 'step': - echo get_post_meta( $id, '_step', true ); + echo get_post_meta( $id, '_step', true ); break; - + case 'cats': $cats = get_post_meta( $id, '_cats', false); - if ( $cats != false and count( $cats[0] ) > 0 ) { + if ( $cats != false and count( $cats[0] ) > 0 ) { foreach ( $cats[0] as $cat ){ - - $taxonomy = 'product_cat'; + + $taxonomy = 'product_cat'; $term = get_term_by( 'id', $cat, $taxonomy ); - $link = get_term_link( $term ); - - echo "" . $term->name . "
"; + $link = get_term_link( $term ); + + echo "" . $term->name . "
"; } - } - break; - + } + break; + case 'product_tags': $tags = get_post_meta( $id, '_tags', false); - if ( $tags != null and count( $tags[0] ) > 0) { + if ( $tags != null and count( $tags[0] ) > 0) { foreach ( $tags[0] as $tag ){ - - $taxonomy = 'product_tag'; + + $taxonomy = 'product_tag'; $term = get_term_by( 'id', $tag, $taxonomy ); - $link = get_term_link( $term ); - - echo "" . $term->name . "
"; + $link = get_term_link( $term ); + + echo "" . $term->name . "
"; } - } + } break; - + case 'roles': $roles = get_post_meta( $id, '_roles', false); - if ( $roles != null and count( $roles[0] ) > 0) { + if ( $roles != null and count( $roles[0] ) > 0) { foreach ( $roles[0] as $role ){ - echo ucfirst( $role ) . "
"; + echo ucfirst( $role ) . "
"; } - } + } break; - + default: break; - } - } - + } + } + /* * Make Custom Columns Sortable - */ - public function sortable_quantity_rule_columns( $columns ) { - + */ + public function sortable_quantity_rule_columns( $columns ) { + $columns['priority'] = __('Priority'); $columns['min'] = __('Minimum'); $columns['max'] = __('Maximum'); $columns['step'] = __('Step Value'); - - return $columns; - } - + + return $columns; + } + /* * Register and Create Rule Options Meta Box for Quantity Rules - */ + */ public function quantity_rule_meta_init() { add_meta_box( - 'wpbo-quantity-rule-meta', - 'Set Quantity Rule Options', - array( $this, 'quantity_rule_meta' ), - 'quantity-rule', - 'normal', + 'wpbo-quantity-rule-meta', + 'Set Quantity Rule Options', + array( $this, 'quantity_rule_meta' ), + 'quantity-rule', + 'normal', 'high' ); } - + public function quantity_rule_meta( $post ) { - + $min = get_post_meta( $post->ID, '_min', true); $max = get_post_meta( $post->ID, '_max', true); $min_oos = get_post_meta( $post->ID, '_min_oos', true ); @@ -190,10 +190,10 @@ public function quantity_rule_meta( $post ) { $max_sale = get_post_meta( $post->ID, '_max_sale', true ); $step = get_post_meta( $post->ID, '_step', true); $priority = get_post_meta( $post->ID, '_priority', true); - + // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_rule_value_nonce' ); - + ?>
@@ -224,10 +224,10 @@ public function quantity_rule_meta( $post ) {

ID, '_cats', false); - + if ( $cats != null ) { $cats = $cats[0]; } - + // Get all possible categories $tax_name = 'product_cat'; - - $args = array( + + $args = array( 'parent' => 0, 'hide_empty' => false ); - + $terms = get_terms( $tax_name, $args ); - + if ( $terms ){ - + // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_tax_nonce' ); - + echo ''; } } - + /* * Will Recursivly Print all Product Categories with heirarcy included */ - public function print_tax_inputs( $term, $taxonomy_name, $cats, $level ) { - + public function print_tax_inputs( $term, $taxonomy_name, $cats, $level ) { + // Echo Single Item ?>
  • term_id, $cats )) echo 'checked="checked"' ?> />name; ?>
  • - term_id, $taxonomy_name ); - + // Continue to print children if they exist if ( $children ){ echo ''; } } - + /* * Allow users to apply rules by tags - */ + */ public function quantity_rule_tag_init() { add_meta_box( 'wpbo-quantity-rule-tag-meta', @@ -314,19 +314,19 @@ public function quantity_rule_tag_init() { 'high' ); } - + public function quantity_rule_tag_meta( $post ) { - + // Get all Tags $args = array( - 'orderby' => 'name', + 'orderby' => 'name', 'order' => 'ASC', - 'hide_empty' => false, - - ); + 'hide_empty' => false, + + ); $tags = get_terms( 'product_tag', $args ); - + $included_tags = get_post_meta( $post->ID, '_tags'); if ( $included_tags != false ){ $included_tags = $included_tags[0]; @@ -334,7 +334,7 @@ public function quantity_rule_tag_meta( $post ) { // If Tags exists, show them all if ( $tags ) { - + // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_tag_nonce' ); @@ -347,13 +347,13 @@ public function quantity_rule_tag_meta( $post ) { - get_names(); - + // Get applied roles $applied_roles = get_post_meta( $post->ID, '_roles' ); if ( $applied_roles != false ){ @@ -378,7 +378,7 @@ public function quantity_rule_role( $post ) { } // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_role_nonce' ); - + if ( $roles ): ?>
    - -
    + +
    @@ -135,8 +135,8 @@ function product_meta_box_content( $post ) { - -
    + +
    @@ -152,7 +152,7 @@ function product_meta_box_content( $post ) { $rule ): ?> @@ -181,7 +181,7 @@ function product_meta_box_content( $post ) { ID, '_wpbo_deactive', true ); $step = get_post_meta( $post->ID, '_wpbo_step', true ); @@ -195,8 +195,8 @@ function product_meta_box_content( $post ) { // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_product_rule_nonce' ); - - // Print the form ?> + + // Print the form ?>
    /> @@ -232,67 +232,65 @@ function product_meta_box_content( $post ) {
    = step */ /* if ( isset( $step ) and isset( $min ) ) { @@ -316,71 +314,69 @@ public function save_quantity_meta_data( $post_id ) { if ( $min != 0 ) { $min = wcqu_validate_number( $min ); } - update_post_meta( - $post_id, - '_wpbo_minimum', + update_post_meta( + $post_id, + '_wpbo_minimum', strip_tags( $min ) ); } - + /* Make sure Max > Min */ if( isset( $_POST['_wpbo_maximum'] ) && ! empty($_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', + + update_post_meta( + $post_id, + '_wpbo_maximum', strip_tags( wcqu_validate_number( $max ) ) ); } - - - + // Update Out of Stock Minimum if( isset( $_POST['_wpbo_minimum_oos'] ) && ! empty($_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', + update_post_meta( + $post_id, + '_wpbo_minimum_oos', strip_tags( $min_oos ) ); } - + // Update Out of Stock Maximum if( isset( $_POST['_wpbo_maximum_oos'] ) && ! empty($_POST['_wpbo_maximum_oos'])) { $max_oos = stripslashes( $_POST['_wpbo_maximum_oos'] ); - + // Allow the value to be unset if ( $max_oos != '' ) { - - // Validate the number + + // 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', + } + + update_post_meta( + $post_id, + '_wpbo_maximum_oos', strip_tags( $max_oos ) ); diff --git a/includes/class-wcqu-validations.php b/includes/class-wcqu-validations.php index 742c483..5f73461 100755 --- a/includes/class-wcqu-validations.php +++ b/includes/class-wcqu-validations.php @@ -1,12 +1,12 @@ -validate_single_product( $passed, $product_id, $quantity, false, $variation_id, $variations ); - + } - + /* * Cart Update Validation to ensure quantity ordered follows the user's rules. * - * @access public + * @access public * @param boolean passed * @param string cart_item_key * @param array values @@ -46,14 +46,14 @@ public function add_to_cart_validation( $passed, $product_id, $quantity, $variat public function update_cart_validation( $passed, $cart_item_key, $values, $quantity ) { return $this->validate_single_product( $passed, $values['product_id'], $quantity, true, $values['variation_id'], $values['variation'] ); - + } - + /* * Validates a single product based on the quantity rules applied to it. * It will also validate based on the quantity in the cart. * - * @access public + * @access public * @param boolean passed * @param int product_id * @param int quantity @@ -61,83 +61,90 @@ public function update_cart_validation( $passed, $cart_item_key, $values, $quant * @param int variation_id * @param array variations * @return boolean - * + * */ public function validate_single_product( $passed, $product_id, $quantity, $from_cart, $variation_id = null, $variations = null ) { global $woocommerce, $product, $WC_Quantities_and_Units; $product = wc_get_product( $product_id ); $title = $product->get_title(); - + // Get the applied rule and values - if they exist $rule = wcqu_get_applied_rule( $product ); - //var_dump($rule); $values = wcqu_get_value_from_rule( 'all', $product, $rule ); - - //var_dump($values); + if ( $values != null ) extract( $values ); // $min_value, $max_value, $step, $priority, $min_oos, $max_oos - - //var_dump($values); + // Inactive Products can be ignored if ( $values == null ) return true; - - // Check if the product is out of stock + + // Check if the product is out of stock $stock = $product->get_stock_quantity(); - + // Adjust min value if item is out of stock if ( strlen( $stock ) != 0 and $stock <= 0 and isset( $min_oos ) and $min_oos != null ) { $min_value = $min_oos; } - + // Adjust max value if item is out of stock if ( strlen( $stock ) != 0 and $stock <= 0 and isset( $max_oos ) and $max_oos != null ) { $max_value = $max_oos; } - + // Min Validation // added $min_value != 0 since List Items starts all products at 0 quantity. - - + if ( $min_value != null && $min_value != 0 && $quantity < $min_value ) { + + if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) { + wc_add_notice( sprintf( __( "You must add a minimum of %s %s's to your cart.", 'woocommerce' ), $min_value, $title ), 'error' ); + + // Old Validation Style Support + } else { + $woocommerce->add_error( sprintf( __( "You must add a minimum of %s %s's to your cart.", 'woocommerce' ), $min_value, $title ) ); + } + + return false; + } + // Max Validation if ( $max_value != null && $quantity > $max_value ) { - + if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) { - wc_add_notice( sprintf( __( "You may only add a maximum of %s %s's to your cart.", 'qau' ), $max_value, $title ), 'error' ); - - // Old Validation Style Support + wc_add_notice( sprintf( __( "You may only add a maximum of %s %s's to your cart.", 'woocommerce' ), $max_value, $title ), 'error' ); + + // Old Validation Style Support } else { - $woocommerce->add_error( sprintf( __( "You may only add a maximum of %s %s's to your cart.", 'qau' ), $max_value, $title ) ); + $woocommerce->add_error( sprintf( __( "You may only add a maximum of %s %s's to your cart.", 'woocommerce' ), $max_value, $title ) ); } return false; } - + // Subtract the min value from quantity to calc remainder if min value exists if ( $min_value != 0 ) { $rem_qty = $quantity - $min_value; - } - else { + } else { $rem_qty = $quantity; } $rem_qty = (float)$rem_qty; $step = (float)$step; - - // Step Validation + + // Step Validation if ( $step != null && wcqu_fmod_round($rem_qty, $step) != 0 ) { - + if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) { - wc_add_notice( sprintf( __( "You may only add a %s in multiples of %s to your cart.", 'qau' ), $title, $step ), 'error' ); - - // Old Validation Style Support + wc_add_notice( sprintf( __( "You may only add a %s in multiples of %s to your cart.", 'woocommerce' ), $title, $step ), 'error' ); + + // Old Validation Style Support } else { - $woocommerce->add_error( sprintf( __( "You may only add a %s in multiples of %s to your cart.", 'qau' ), $title, $step ) ); + $woocommerce->add_error( sprintf( __( "You may only add a %s in multiples of %s to your cart.", 'woocommerce' ), $title, $step ) ); } - + return false; } - + // Don't run Cart Validations if user is updating the cart if ( $from_cart != true ) { //Cart Categories default Quantity @@ -168,30 +175,30 @@ public function validate_single_product( $passed, $product_id, $quantity, $from_ //var_dump($cart_cats); //exit(); // If there aren't any items in the cart already, ignore these validations - if ( isset( $cart_qty ) and $cart_qty != null) { - + if ( isset( $cart_qty ) and $cart_qty != null ) { + // Total Cart Quantity Min Validation if ( $min_value != null && ( $quantity + $cart_qty ) < $min_value ) { - + if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) { - wc_add_notice( sprintf( __( "Your cart must have a minimum of %s %s's to proceed.", 'qau' ), $min_value, $title ), 'error' ); - - // Old Validation Style Support + wc_add_notice( sprintf( __( "Your cart must have a minimum of %s %s's to proceed.", 'woocommerce' ), $min_value, $title ), 'error' ); + + // Old Validation Style Support } else { - $woocommerce->add_error( sprintf( __( "Your cart must have a minimum of %s %s's to proceed.", 'qau' ), $min_value, $title ) ); + $woocommerce->add_error( sprintf( __( "Your cart must have a minimum of %s %s's to proceed.", 'woocommerce' ), $min_value, $title ) ); } return false; } - + // Total Cart Quantity Max Validation if ( $max_value != null && ( $quantity + $cart_qty ) > $max_value ) { - + if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) { - wc_add_notice( sprintf( __( "You can only purchase a maximum of %s %s's at once and your cart has %s %s's in it already.", 'qau' ), $max_value, $title, $cart_qty, $title ), 'error' ); - - // Old Validation Style Support + wc_add_notice( sprintf( __( "You can only purchase a maximum of %s %s's at once and your cart has %s %s's in it already.", 'woocommerce' ), $max_value, $title, $cart_qty, $title ), 'error' ); + + // Old Validation Style Support } else { - $woocommerce->add_error( sprintf( __( "You can only purchase a maximum of %s %s's at once and your cart has %s %s's in it already.", 'qau' ), $max_value, $title, $cart_qty, $title ) ); + $woocommerce->add_error( sprintf( __( "You can only purchase a maximum of %s %s's at once and your cart has %s %s's in it already.", 'woocommerce' ), $max_value, $title, $cart_qty, $title ) ); } return false; } @@ -215,14 +222,14 @@ public function validate_single_product( $passed, $product_id, $quantity, $from_ } else { $cart_qty_rem = $quantity + $cart_qty; } - + // Total Cart Quantity Step Validation $cart_qty_rem = (float)$cart_qty_rem; if ( $step != null && $step != 0 && $cart_qty_rem != 0 && wcqu_fmod_round($cart_qty_rem, $step) != 0 ) { if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) { - wc_add_notice( sprintf( __("You may only purchase %s in multiples of %s.", 'qau' ), $title, $step ), 'error' ); - - // Old Validation Style Support + wc_add_notice( sprintf( __("You may only purchase %s in multiples of %s.", 'woocommerce' ), $title, $step ), 'error' ); + + // Old Validation Style Support } else { $woocommerce->add_error( sprintf( __("You may only purchase %s in multiples of %s.", 'qau' ), $title, $step ) ); } diff --git a/includes/wcqu-functions.php b/includes/wcqu-functions.php index 9eef764..5222691 100755 --- a/includes/wcqu-functions.php +++ b/includes/wcqu-functions.php @@ -1,21 +1,21 @@ -id, '_wpbo_deactive', true ) == 'on' ) { return 'inactive'; - + } elseif ( get_post_meta( $product->id, '_wpbo_override', true ) == 'on' ) { $rule = wcqu_get_applied_rule_obj( $product, $role ); $rule->rule_status = 'override'; @@ -23,7 +23,7 @@ function wcqu_get_applied_rule( $product, $role = null ) { } elseif ( isset( $options['ipq_site_rule_active'] ) and $options['ipq_site_rule_active'] == 'on' ) { return 'sitewide'; - + } else { return wcqu_get_applied_rule_obj( $product, $role ); } @@ -35,13 +35,13 @@ function wcqu_get_applied_rule( $product, $role = null ) { * * @params object $product WC_Product object * @param string User role to get rule from, otherwise current user role is used -* @return mixed Null if no rule applies / Object top rule post +* @return mixed Null if no rule applies / Object top rule post */ function wcqu_get_applied_rule_obj( $product, $role = null ) { // Get Product Terms $product_cats = wp_get_post_terms( $product->id, 'product_cat' ); - $product_tags = wp_get_post_terms( $product->id, 'product_tag' ); + $product_tags = wp_get_post_terms( $product->id, 'product_tag' ); // Get role if not passed if(!is_user_logged_in()) { @@ -57,56 +57,58 @@ function wcqu_get_applied_rule_obj( $product, $role = null ) { // Combine all product terms $product_terms = array_merge( $product_cats, $product_tags ); + // Check for rule / role transient if ( false === ( $rules = get_transient( 'ipq_rules_' . $role ) ) ) { + // Get all Rules $args = array( 'posts_per_page' => -1, 'post_type' => 'quantity-rule', 'post_status' => 'publish', - ); - + ); + $rules = get_posts( $args ); - + // Remove rules not applied to current user role - $cnt = 0; + $cnt = 0; $rules_to_unset = array(); - + while ( $cnt < count( $rules ) ) { - + $roles = get_post_meta( $rules[$cnt]->ID, '_roles' ); if ( !in_array( $role, $roles[0] ) && !empty($roles[0])) { array_push( $rules_to_unset, $cnt ); - } - + } + $cnt++; - } + } $duration = 60 * 60 * 12; // 12 hours arsort( $rules_to_unset ); - + foreach ( $rules_to_unset as $single_unset ) { unset( $rules[$single_unset] ); - } - set_transient( 'ipq_rules_' . $role, $rules, $duration ); - } + } + set_transient( 'ipq_rules_' . $role, $rules, $duration ); + } $top = null; $top_rule = new StdClass(); // Loop through the rules and find the ones that apply foreach ( $rules as $rule ) { - + $apply_rule = false; - + // Get the Rule's Cats and Tags $cats = get_post_meta( $rule->ID, '_cats' ); $tags = get_post_meta( $rule->ID, '_tags' ); $roles = get_post_meta( $rule->ID, '_roles' ); - + if( $cats != false ) $cats = $cats[0]; - + if( $tags != false ) $tags = $tags[0]; @@ -122,11 +124,11 @@ function wcqu_get_applied_rule_obj( $product, $role = null ) { $apply_rule = true; } } - + // If the rule applies, check the priority if ( $apply_rule == true ) { - - $priority = get_post_meta( $rule->ID, '_priority', true ); + + $priority = get_post_meta( $rule->ID, '_priority', true ); if( $priority != '' and $top > $priority or $top == null ) { $top = $priority; @@ -135,24 +137,25 @@ function wcqu_get_applied_rule_obj( $product, $role = null ) { } } - return $top_rule; + return $top_rule; } /* * Get the Input Value (min/max/step/priority/role/all) for a product given a rule * * @params string $type Product type -* @params object $product Product Object +* @params object $product Product Object * @params object $rule Quantity Rule post object * @return mixed */ function wcqu_get_value_from_rule( $type, $product, $rule ) { + // Validate $type - if ( $type != 'min' and - $type != 'max' and - $type != 'step' and - $type != 'all' and - $type != 'priority' and + if ( $type != 'min' and + $type != 'max' and + $type != 'step' and + $type != 'all' and + $type != 'priority' and $type != 'role' and $type != 'min_oos' and $type != 'max_oos' and @@ -162,15 +165,15 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { $type != 'max_sale' ) { return null; - - // Validate for missing rule + + // Validate for missing rule } elseif ( $rule == null ) { return null; - + // Return Null if Inactive } elseif ( $rule == 'inactive' ) { return null; - + // Return Product Meta if Override is on } elseif ( isset($rule->rule_status) && $rule->rule_status == 'override' ) { @@ -179,7 +182,7 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { // Check if the product is under stock management and out of stock if ( strlen( $stock ) != 0 and $stock <= 0 ) { - + // Return Out of Stock values if they exist switch ( $type ) { case 'min': @@ -187,16 +190,16 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { if ( $min_oos != '' ) return $min_oos; break; - + case 'max': $max_oos = get_post_meta( $product->id, '_wpbo_maximum_oos', true ); if ( $max_oos != '' ) return $max_oos; - break; - } + break; + } // If nothing was returned, proceed as usual } - + switch ( $type ) { case 'all': $value = array( @@ -228,19 +231,19 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { case 'min': return get_post_meta( $product->id, '_wpbo_minimum', true ); break; - - case 'max': + + case 'max': return get_post_meta( $product->id, '_wpbo_maximum', true ); break; - + case 'step': return get_post_meta( $product->id, '_wpbo_step', true ); break; - + case 'min_oos': return get_post_meta( $product->id, '_wpbo_minimum_oos', true ); break; - + case 'max_oos': return get_post_meta( $product->id, '_wpbo_maximum_oos', true ); break; @@ -264,13 +267,13 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { case 'priority': return null; break; - } - + } + // Check for Site Wide Rule } elseif ( $rule == 'sitewide' ) { $options = get_option( 'ipq_options' ); - + if( isset( $options['ipq_site_min'] ) ) { $min = $options['ipq_site_min']; } else { @@ -288,59 +291,59 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { } else { $min_oos = ''; } - + if( isset( $options['ipq_site_max_oos'] ) ) { $max_oos = $options['ipq_site_max_oos']; } else { $max_oos = ''; } - + if( isset( $options['ipq_site_step'] ) ) { $step = $options['ipq_site_step']; } else { - $step = ''; + $step = ''; } switch ( $type ) { case 'all': - return array( - 'min_value' => $min, + return array( + 'min_value' => $min, 'max_value' => $max, 'min_oos' => $min_oos, 'max_oos' => $max_oos, 'step' => $step ); break; - + case 'min': - return array( 'min' => $min ); + return array( 'min' => $min ); break; - - case 'max': - return array( 'max' => $max ); + + case 'max': + return array( 'max' => $max ); break; - - case 'min_oos': - return array( 'min_oos' => $min_oos ); + + case 'min_oos': + return array( 'min_oos' => $min_oos ); break; - - case 'max_oos': - return array( 'max_oos' => $max_oos ); + + case 'max_oos': + return array( 'max_oos' => $max_oos ); break; - + case 'step': - return array( 'step' => $step ); + return array( 'step' => $step ); break; - + case 'priority': return null; break; - + } - + // Return Values from the Rule based on $type requested } else { - + switch ( $type ) { case 'all': //TODO: why get all and filter array? @@ -360,31 +363,31 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { 'max_sale' => get_post_meta( $rule->ID, '_max_sale', true ), ); break; - + case 'min': return get_post_meta( $rule->ID, '_min', true ); break; - - case 'max': + + case 'max': return get_post_meta( $rule->ID, '_max', true ); break; - - case 'min_oos': + + case 'min_oos': return get_post_meta( $rule->ID, '_min_oos', true ); break; - - case 'max_oos': + + case 'max_oos': return get_post_meta( $rule->ID, '_max_oos', true ); break; - + case 'step': return get_post_meta( $rule->ID, '_step', true ); break; - + case 'role': return get_post_meta( $rule->ID, '_roles', true ); break; - + case 'priority': return get_post_meta( $rule->ID, '_priority', true ); break; @@ -412,21 +415,22 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { * Validate inputs as numbers and set them to null if 0 */ function wcqu_validate_number( $number ) { + $number = stripslashes( $number ); - // $number = intval( $number ); - +// $number = intval( $number ); + if ( $number == 0 ) { return null; } elseif ( $number < 0 ) { return null; - } - + } + return $number; } /** * Provides a fmod function that actually works as intended. - * + * * @param float $x The dividend * @param float $y The divisor * @@ -475,8 +479,8 @@ function wpbo_get_value_from_rule( $type, $product, $rule ) { /** - * This is ugly, but we need to pretend that the pre-forked version of this plugin is active since Thumbnail Quantities - * does a check whether it active. It'd be nice if they just made it a filter instead. Also TQ has some incorrect + * This is ugly, but we need to pretend that the pre-forked version of this plugin is active since Thumbnail Quantities + * does a check whether it active. It'd be nice if they just made it a filter instead. Also TQ has some incorrect * javascript rounding on decimal values, so we may just have to fork it at some point as well. */ add_filter( 'active_plugins', function($plugins){ diff --git a/quantites-and-units.php b/quantites-and-units.php index b1bf71a..ebbbc56 100755 --- a/quantites-and-units.php +++ b/quantites-and-units.php @@ -3,7 +3,7 @@ Plugin Name: Quantities and Units for WooCommerce Plugin URI: https://wordpress.org/plugins/quantities-and-units-for-woocommerce/ Description: Easily require your customers to buy a minimum / maximum / incremental amount of products to continue with their checkout. -Version: 1.0.10 +Version: 1.0.13 Author: Nicholas Verwymeren Author URI: https://www.nickv.codes Text Domain: qau diff --git a/readme.txt b/readme.txt index 203476d..7b49be8 100755 --- a/readme.txt +++ b/readme.txt @@ -1,18 +1,23 @@ === Quantities and Units for WooCommerce === Contributors: greatwitenorth Tags: woocommerce, product quantities, product minimum values, product maximum values, product step values, incremental product quantities, min, max, decimal +Donate link: https://www.nickv.codes/donate Requires at least: 3.5 Tested up to: 4.3 -Stable tag: 1.0.10 +Stable tag: 1.0.13 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html -Easily require your customers to buy a minimum / maximum / incremental amount of products to continue with their checkout. +Easily require your customers to buy a minimum / maximum / incremental amount of products. Supports decimal quantities. == Description == -NOTE: This plugin has been forked from the "Advanced Product Quantities" plugin. It adds decimal quantities support and units to products. +NOTE: This plugin has been forked from the "Advanced Product Quantities" plugin. It adds decimal quantities support and +units to products. Please don't attempt to run both plugins simultaneously. It not needed and the universe will +probably implode. -With Quantities and Units for WooCommerce you can easily create rules that restrict the amount of products a user can buy at once. Set Minimum, Maximum and Step values for any product type and must be valid before a customer can proceed to checkout. +With Quantities and Units for WooCommerce you can easily create rules that restrict the amount of products a user can +buy at once. Set Minimum, Maximum and Step values for any product type and must be valid before a customer can proceed +to checkout. Quantities and Units also bring decimal quantity support to WooCommerce. This plugin works great with [Rapid Order](http://rapidorderplugin.com/), a fast ordering system for WooCommerce. @@ -29,7 +34,6 @@ Features: * Improved performance / caching * Improved admin interface * Allows rules to have a minimum of 0 -* Get started in minutes * Set a Minimum product quantity requirement * Set a Maximum product quantity requirement * Sell products by a desired increment ie. by two's or the dozen @@ -38,7 +42,7 @@ Features: * Set rule priority to layer multiple rules on top of each other * Add your rule based input boxes to products thumbnails using [WooCommerce Thumbnail Input Quantities](http://wordpress.org/plugins/woocommerce-thumbnail-input-quantities/installation/) * Easily override rules on a per-product basis -* Integrates with [WooCommerce's Product CSV Import Suite](http://www.woothemes.com/products/product-csv-import-suite/?utm_source=docs&utm_medium=docssite&utm_campaign=docs) +* Integrates with [WooCommerce's Product CSV Import Suite](http://www.woothemes.com/products/product-csv-import-suite/) * See which rule is being applied to an individual product on your edit product page * Now fully supports ALL PRODUCT TYPES, simple, variable, grouped and affiliate * Create Site Wide rules that apply to every product unless overwritten on a per-product basis @@ -66,6 +70,15 @@ Manual Installation 6. Set Rules for categories by clicking the new ‘Quantity Rules’ sidebar option or assign per-product rules by using the new metabox on your product page. == Changelog == += 1.0.13 = +* Fixed input issue introduced in 10.0.12 release + += 1.0.12 = +* Fixed an issue where sometimes the correct value would not display when using decimal quantities. + += 1.0.11 = +* Fixed issue with max value causing amount not to increment correctly in some circumstances. + = 1.0.10 = * fixed an issue with role based quantities not working * fixed bug with sitewide rules @@ -103,88 +116,6 @@ Manual Installation * Allow decimal quantities * Specify a unit of measurement for the quantity (ie lbs, kg, bag etc) -= APQ 2.1.6 = -* Hides message when no quantity rule is being applied. - -= APQ 2.1.5 = -* Minor bug fix, couldn't unset max out of stock value - -= APQ 2.1.4 = -* Upgrade fix, removed error for unset value - -= APQ 2.1.3 = -* Added Quantity Message Options -* Added Out of Stock min/max values -* Fixed 0 quantity appearing as 1 bug -* Minor class tweaks - -= APQ 2.1.2 = -* Default user role bug fix. - -= APQ 2.1.1 = -* Product Page UI Update -* Minor bug fixes. - -= APQ 2.1.0 = -* Added Role Support, create rules based on user roles. -* Improved performance / cacheing -* Improved admin interface -* Allows rules to have a minimum of 0 - -= APQ 2.0.0 = -* Updated name from WooCommerce Incremental Product Quantities to WooCommerce Advanced Product Quantities -* Now fully supports ALL PRODUCT TYPES, simple, variable, grouped and affiliate -* Create Site Wide rules that apply to every product unless overwritten on a per-product basis -* Create rules by Product Tags (opposed to just categories) -* Code reconfiguration puts everything into classes, the way it should be. - -= APQ 1.1.4 = -* Added back WC 2.0.x validation compatibility. - -= APQ 1.1.3 = -* Minor bug fixes. - -= APQ 1.1.2 = -* Undefined variable bug fix. - -= APQ 1.1.1 = -* Fixed bug that was unsetting rule checkboxes. - -= APQ 1.1.0 = -* Updated plugin to work with WC 2.1.2 and below. -* New error response methods. -* Update validations. -* Updated comments. -* Added extra help text. - -= APQ 1.0.8 = -* Fixed division by zero error in validations. - -= APQ 1.0.7 = -* Contributor consolidation. - -= APQ 1.0.6 = -* Fixed cart bug, added additional validation so users can't enter minimum values that are less then the step value. - -= APQ 1.0.5 = -* Fixed additional bug related to missing input values and error messages on some installs. Also updated notice window. - -= APQ 1.0.4 = -* Style sheet and link update. -* Added potential solution for niche validation problem. - -= APQ 1.0.3 = -* Readme.txt updates. - -= APQ 1.0.2 = -* Another small url change. - -= APQ 1.0.1 = -* Minor variable updates to account for changing directory. - -= APQ 1.0.0 = -* Initial Commit - == Screenshots == 1. Single product page, page loads with it's minimum quantity and notifies the user below.