@@ -66,4 +66,4 @@ public function save_unit_meta_data( $post_id ) {
endif;
-return new WC_Quantities_and_Units_Units_Box();
\ No newline at end of file
+return new WC_Quantities_and_Units_Units_Box();
diff --git a/includes/class-wcqu-validations.php b/includes/class-wcqu-validations.php
index 8b1461e..742c483 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,146 +61,188 @@ 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 = get_product( $product_id );
+
+ $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.", 'woocommerce' ), $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.", 'qau' ), $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.", 'woocommerce' ), $max_value, $title ) );
+ $woocommerce->add_error( sprintf( __( "You may only add a maximum of %s %s's to your cart.", 'qau' ), $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.", 'woocommerce' ), $title, $step ), 'error' );
-
- // Old Validation Style Support
+ 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
} else {
- $woocommerce->add_error( sprintf( __( "You may only add a %s in multiples of %s to your cart.", 'woocommerce' ), $title, $step ) );
+ $woocommerce->add_error( sprintf( __( "You may only add a %s in multiples of %s to your cart.", 'qau' ), $title, $step ) );
}
-
+
return false;
}
-
+
// Don't run Cart Validations if user is updating the cart
if ( $from_cart != true ) {
-
+ //Cart Categories default Quantity
+ $cart_cats = array(
+ 'qty' => 0,
+ 'terms_name' => ''
+ );
// Get Cart Quantity for the product
foreach( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
+ //Get Cart Categories Quantity
+ if($cats) {
+ $cart_prod_terms = get_the_terms( $values['product_id'], 'product_cat' );
+ foreach ($cart_prod_terms as $term) {
+ if(in_array($term->term_id, $cats)) {
+ $cart_cats['qty'] += $values['quantity'];
+ if(strpos($cart_cats['terms_name'], $term->name) === FALSE)
+ $cart_cats['terms_name'] .= $term->name.', ';
+ }
+ }
+ }
+
$_product = $values['data'];
if( $product_id == $_product->id ) {
$cart_qty = $values['quantity'];
}
}
-
+ $cart_cats['terms_name'] = trim($cart_cats['terms_name'] ,', ');
+ //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.", 'woocommerce' ), $min_value, $title ), 'error' );
-
- // Old Validation Style Support
+ 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
} else {
- $woocommerce->add_error( sprintf( __( "Your cart must have a minimum of %s %s's to proceed.", 'woocommerce' ), $min_value, $title ) );
+ $woocommerce->add_error( sprintf( __( "Your cart must have a minimum of %s %s's to proceed.", 'qau' ), $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.", 'woocommerce' ), $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.", 'qau' ), $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.", 'woocommerce' ), $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.", 'qau' ), $max_value, $title, $cart_qty, $title ) );
}
return false;
}
-
+
+ // Total Cart Quantity Max Sale Validation
+ if ( $max_sale != null && ( $quantity + $cart_qty ) > $max_sale ) {
+
+ if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) {
+ wc_add_notice( sprintf( __( "You can only purchase a maximum of %s %s's in sale at once and your cart has %s %s's in it already.", 'qau' ), $max_sale, $title, $cart_qty, $title ), 'error' );
+
+ // Old Validation Style Support
+ } else {
+ $woocommerce->add_error( sprintf( __( "You can only purchase a maximum of %s %s's in sale at once and your cart has %s %s's in it already.", 'qau' ), $max_sale, $title, $cart_qty, $title ) );
+ }
+ return false;
+ }
+
// Subtract the min value from cart quantity to calc remainder if min value exists
if ( $min_value != 0 ) {
$cart_qty_rem = $quantity + $cart_qty - $min_value;
} 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.", 'woocommerce' ), $title, $step ), 'error' );
-
- // Old Validation Style Support
+ wc_add_notice( sprintf( __("You may only purchase %s in multiples of %s.", 'qau' ), $title, $step ), 'error' );
+
+ // Old Validation Style Support
+ } else {
+ $woocommerce->add_error( sprintf( __("You may only purchase %s in multiples of %s.", 'qau' ), $title, $step ) );
+ }
+ return false;
+ }
+ }
+
+ if($cart_cats['qty'] > 0) {
+ $max_value = $max_value ? $max_value : $max_value_p;
+ //$min_value = $min_value ? $min_value : $min_value_p;
+
+ // Total Cart Quantity Max Validation
+ if ( $max_value != null && ( $quantity + $cart_cats['qty'] ) > $max_value ) {
+
+ if ( $WC_Quantities_and_Units->wc_version >= 2.1 ) {
+ wc_add_notice( sprintf( __( "You can only purchase a maximum of %s products from %s categories at once and your cart has %s items from %s categories in it already.", 'qau' ), $max_value, $cart_cats['terms_name'], $cart_cats['qty'], $cart_cats['terms_name'] ), 'error' );
+
+ // Old Validation Style Support
} else {
- $woocommerce->add_error( sprintf( __("You may only purchase %s in multiples of %s.", 'woocommerce' ), $title, $step ) );
+ $woocommerce->add_error( sprintf( __( "You can only purchase a maximum of %s products from %s categories at once and your cart has %s items from %s categories in it already.", 'qau' ), $max_value, $cart_cats['terms_name'], $cart_cats['qty'], $cart_cats['terms_name'] ) );
}
return false;
}
diff --git a/includes/wcqu-functions.php b/includes/wcqu-functions.php
index b150f58..9eef764 100755
--- a/includes/wcqu-functions.php
+++ b/includes/wcqu-functions.php
@@ -1,27 +1,29 @@
-id, '_wpbo_deactive', true ) == 'on' ) {
return 'inactive';
-
+
} elseif ( get_post_meta( $product->id, '_wpbo_override', true ) == 'on' ) {
- return 'override';
-
+ $rule = wcqu_get_applied_rule_obj( $product, $role );
+ $rule->rule_status = 'override';
+ return $rule;
+
} 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 );
}
@@ -33,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()) {
@@ -48,65 +50,63 @@ function wcqu_get_applied_rule_obj( $product, $role = null ) {
$user_data = get_userdata( get_current_user_id() );
if ( $user_data->roles ) {
foreach ( $user_data->roles as $cap => $val ) {
- $role = $cap;
+ $role = $val;
}
}
}
// 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 = 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 +122,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,48 +135,51 @@ 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'
+ $type != 'max_oos' and
+ $type != 'cats' and
+ $type != 'tags' and
+ $type != 'min_sale' and
+ $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 ( $rule == 'override' ) {
-
+} elseif ( isset($rule->rule_status) && $rule->rule_status == 'override' ) {
+
// Check if the product is out of stock
$stock = $product->get_stock_quantity();
// 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':
@@ -184,56 +187,90 @@ 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':
- return array(
- 'min_value' => get_post_meta( $product->id, '_wpbo_minimum', true ),
- 'max_value' => get_post_meta( $product->id, '_wpbo_maximum', true ),
- 'step' => get_post_meta( $product->id, '_wpbo_step', true ),
- 'min_oos' => get_post_meta( $product->id, '_wpbo_minimum_oos', true ),
- 'max_oos' => get_post_meta( $product->id, '_wpbo_maximum_oos', true ),
- );
+ $value = array(
+ 'min_value' => get_post_meta( $product->id, '_wpbo_minimum', true ),
+ 'max_value' => get_post_meta( $product->id, '_wpbo_maximum', true ),
+ 'step' => get_post_meta( $product->id, '_wpbo_step', true ),
+ 'min_oos' => get_post_meta( $product->id, '_wpbo_minimum_oos', true ),
+ 'max_oos' => get_post_meta( $product->id, '_wpbo_maximum_oos', true ),
+ 'min_sale' => get_post_meta( $product->id, '_wpbo_minimum_sale', true ),
+ 'max_sale' => get_post_meta( $product->id, '_wpbo_maximum_sale', true ),
+ //'roles' => get_post_meta( $rule->ID, '_roles', true ),
+ 'cats' => get_post_meta( $rule->ID, '_cats', true ),
+ 'tags' => get_post_meta( $rule->ID, '_tags', true ),
+ );
+
+ if(isset($value['cats']) || isset($value['tags'])) {
+ $value['min_value_p'] = get_post_meta( $rule->ID, '_min', true );
+ $value['max_value_p'] = get_post_meta( $rule->ID, '_max', true );
+ $value['min_oos_p'] = get_post_meta( $rule->ID, '_min_oos', true );
+ $value['max_oos_p'] = get_post_meta( $rule->ID, '_max_oos', true );
+ $value['step_p'] = get_post_meta( $rule->ID, '_step', true );
+ //$value['min_sale_p'] = get_post_meta( $rule->ID, '_min_sale', true );
+ //$value['max_sale_p'] = get_post_meta( $rule->ID, '_max_sale', true );
+ }
+
+ return $value;
+
break;
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;
-
+
+ case 'cats':
+ return get_post_meta( $rule->ID, '_tags', true );
+ break;
+
+ case 'tags':
+ return get_post_meta( $rule->ID, '_cats', true );
+ break;
+
+ case 'min_sale':
+ return get_post_meta( $product->id, '_wpbo_minimum_sale', true );
+ break;
+
+ case 'max_sale':
+ return get_post_meta( $product->id, '_wpbo_maximum_sale', true );
+ break;
+
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 {
@@ -251,100 +288,123 @@ 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':
- return array(
+ //TODO: why get all and filter array?
+ //$meta = get_post_meta( $rule->ID, null, true );
+
+ return array(
'min_value' => get_post_meta( $rule->ID, '_min', true ),
'max_value' => get_post_meta( $rule->ID, '_max', true ),
'min_oos' => get_post_meta( $rule->ID, '_min_oos', true ),
'max_oos' => get_post_meta( $rule->ID, '_max_oos', true ),
'step' => get_post_meta( $rule->ID, '_step', true ),
'priority' => get_post_meta( $rule->ID, '_priority', true ),
- 'roles' => get_post_meta( $rule->ID, '_roles', true )
+ 'roles' => get_post_meta( $rule->ID, '_roles', true ),
+ 'cats' => get_post_meta( $rule->ID, '_cats', true ),
+ 'tags' => get_post_meta( $rule->ID, '_tags', true ),
+ 'min_sale' => get_post_meta( $rule->ID, '_min_sale', true ),
+ '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;
- }
+
+ case 'cats':
+ return get_post_meta( $rule->ID, '_tags', true );
+ break;
+
+ case 'tags':
+ return get_post_meta( $rule->ID, '_cats', true );
+ break;
+
+ case 'min_sale':
+ return get_post_meta( $rule->ID, '_min_sale', true );
+ break;
+
+ case 'max_sale':
+ return get_post_meta( $rule->ID, '_max_sale', true );
+ break;
+ }
}
}
@@ -352,22 +412,21 @@ 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
*
@@ -416,8 +475,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/languages/default.pot b/languages/default.pot
new file mode 100644
index 0000000..84148a4
--- /dev/null
+++ b/languages/default.pot
@@ -0,0 +1,103 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Quantities and units for woocommerce\n"
+"POT-Creation-Date: 2016-08-13 18:01+0100\n"
+"PO-Revision-Date: 2016-08-13 18:05+0100\n"
+"Last-Translator: steppade\n"
+"Language-Team: \n"
+"Language: English\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.5.4\n"
+"X-Poedit-KeywordsList: _;gettext;gettext_noop;__\n"
+"X-Poedit-Basepath: /home/gine/Code/01_wordpress/www.tiportolaspesa.it/wp-"
+"content/plugins/quantities-and-units-for-woocommerce/\n"
+"X-Poedit-SourceCharset: UTF-8\n"
+"X-Poedit-SearchPath-0: includes\n"
+
+#: includes/class-wcqu-product-unit.php:105
+msgid "Unit"
+msgstr ""
+
+#: includes/class-wcqu-validations.php:103
+#: includes/class-wcqu-validations.php:107
+#, php-format
+msgid "You must add a minimum of %s %s's to your cart."
+msgstr ""
+
+#: includes/class-wcqu-validations.php:117
+#: includes/class-wcqu-validations.php:121
+#, php-format
+msgid "You may only add a maximum of %s %s's to your cart."
+msgstr ""
+
+#: includes/class-wcqu-validations.php:140
+#: includes/class-wcqu-validations.php:144
+#, php-format
+msgid "You may only add a %s in multiples of %s to your cart."
+msgstr ""
+
+#: includes/class-wcqu-validations.php:185
+#: includes/class-wcqu-validations.php:189
+#, php-format
+msgid "Your cart must have a minimum of %s %s's to proceed."
+msgstr ""
+
+#: includes/class-wcqu-validations.php:198
+#: includes/class-wcqu-validations.php:202
+#, php-format
+msgid ""
+"You can only purchase a maximum of %s %s's at once and your cart has %s %s's "
+"in it already."
+msgstr ""
+
+#: includes/class-wcqu-validations.php:218
+#: includes/class-wcqu-validations.php:222
+#, php-format
+msgid "You may only purchase %s in multiples of %s."
+msgstr ""
+
+#: includes/class-wcqu-validations.php:233
+#: includes/class-wcqu-validations.php:237
+#, php-format
+msgid ""
+"You can only purchase a maximum of %s products from %s categories at once "
+"and your cart has %s items from %s categories in it already."
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:81 includes/class-wcqu-post-type.php:163
+msgid "Priority"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:82 includes/class-wcqu-post-type.php:164
+msgid "Minimum"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:83 includes/class-wcqu-post-type.php:165
+msgid "Maximum"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:84 includes/class-wcqu-post-type.php:166
+msgid "Step Value"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:85
+msgid "Categories"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:86
+msgid "Tags"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:87
+msgid "Roles"
+msgstr ""
+
+#: includes/class-wcqu-post-type.php:88
+msgid "Date"
+msgstr ""
+
+#: includes/class-wcqu-product-meta-box.php:29
+msgid "Product Quantity Rules"
+msgstr ""
diff --git a/languages/qau-it_IT.mo b/languages/qau-it_IT.mo
new file mode 100644
index 0000000..b971730
Binary files /dev/null and b/languages/qau-it_IT.mo differ
diff --git a/languages/qau-it_IT.po b/languages/qau-it_IT.po
new file mode 100644
index 0000000..635938e
--- /dev/null
+++ b/languages/qau-it_IT.po
@@ -0,0 +1,129 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Quantities and units for woocommerce\n"
+"POT-Creation-Date: 2016-08-13 18:01+0100\n"
+"PO-Revision-Date: 2016-08-13 18:19+0100\n"
+"Last-Translator: steppade\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.5.4\n"
+"X-Textdomain-Support: yes\n"
+"X-Poedit-KeywordsList: _;gettext;gettext_noop;__\n"
+"X-Poedit-Basepath: ..\n"
+"X-Poedit-SourceCharset: UTF-8\n"
+"Language: Italian\n"
+"X-Poedit-SearchPath-0: includes\n"
+
+#@ qau
+#: ../includes/class-wcqu-product-unit.php:105
+msgid "Unit"
+msgstr "Unità"
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:103
+#: ../includes/class-wcqu-validations.php:107
+#, php-format
+msgid "You must add a minimum of %s %s's to your cart."
+msgstr "Devi aggiungere un minimo di %s %s al tuo carrello."
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:117
+#: ../includes/class-wcqu-validations.php:121
+#, php-format
+msgid "You may only add a maximum of %s %s's to your cart."
+msgstr "Puoi aggiungere un massimo di %s %s al tuo carrello."
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:140
+#: ../includes/class-wcqu-validations.php:144
+#, php-format
+msgid "You may only add a %s in multiples of %s to your cart."
+msgstr "Puoi aggiungere solo un multiplo di %s di %s al tuo carrello."
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:185
+#: ../includes/class-wcqu-validations.php:189
+#, php-format
+msgid "Your cart must have a minimum of %s %s's to proceed."
+msgstr ""
+"Il tuo carrello deve avere un minimo di %s %s per procedere all'acquisto."
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:198
+#: ../includes/class-wcqu-validations.php:202
+#, php-format
+msgid ""
+"You can only purchase a maximum of %s %s's at once and your cart has %s %s's "
+"in it already."
+msgstr ""
+"Puoi acquistare solo un massimo di %s %s alla volta e nel tuo carrello hai "
+"già %s %s."
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:218
+#: ../includes/class-wcqu-validations.php:222
+#, php-format
+msgid "You may only purchase %s in multiples of %s."
+msgstr "Puoi acquistare solo %s in multipli di %s."
+
+#@ qau
+#: ../includes/class-wcqu-validations.php:233
+#: ../includes/class-wcqu-validations.php:237
+#, php-format
+msgid ""
+"You can only purchase a maximum of %s products from %s categories at once "
+"and your cart has %s items from %s categories in it already."
+msgstr ""
+"Puoi comprare solo un massimo di %s prodotti alla volta appartenenti alle "
+"categorie %s. Nel tuo carrello hai già %s prodotti dalle categorie %s."
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:81
+#: ../includes/class-wcqu-post-type.php:163
+msgid "Priority"
+msgstr "Priorità"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:82
+#: ../includes/class-wcqu-post-type.php:164
+msgid "Minimum"
+msgstr "Minimo"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:83
+#: ../includes/class-wcqu-post-type.php:165
+msgid "Maximum"
+msgstr "Massimo"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:84
+#: ../includes/class-wcqu-post-type.php:166
+msgid "Step Value"
+msgstr "Valore multipli"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:85
+msgid "Categories"
+msgstr "Categorie"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:86
+msgid "Tags"
+msgstr "Tags"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:87
+msgid "Roles"
+msgstr "Ruoli"
+
+#@ qau
+#: ../includes/class-wcqu-post-type.php:88
+msgid "Date"
+msgstr "Data"
+
+#@ qau
+#: ../includes/class-wcqu-product-meta-box.php:29
+msgid "Product Quantity Rules"
+msgstr "Regole di quantità per i prodotti"
diff --git a/quantites-and-units.php b/quantites-and-units.php
index 6c3cc97..b1bf71a 100755
--- a/quantites-and-units.php
+++ b/quantites-and-units.php
@@ -6,22 +6,24 @@
Version: 1.0.10
Author: Nicholas Verwymeren
Author URI: https://www.nickv.codes
-*/
+Text Domain: qau
+Domain Path: /languages
+*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WC_Quantities_and_Units' ) ) :
class WC_Quantities_and_Units {
-
+
public $wc_version;
-
+
/**
* @var WooCommerce Supplier instance
* @since 2.1
*/
protected static $_instance = null;
-
+
/**
* Main Incremental Product Quantities Instance
*
@@ -33,14 +35,14 @@ public static function instance() {
}
return self::$_instance;
}
-
+
public function __construct() {
-
+
// Activation / Deactivation Hooks
register_activation_hook( __FILE__, array( $this, 'activation_hook' ) );
register_activation_hook( __FILE__, array( $this, 'update_rules_with_roles' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation_hook' ) );
-
+
// Include Required Files
require_once( 'includes/wcqu-functions.php' );
require_once( 'includes/class-wcqu-filters.php' );
@@ -51,18 +53,20 @@ public function __construct() {
require_once( 'includes/class-wcqu-advanced-rules.php' );
require_once( 'includes/class-wcqu-units-box.php' );
require_once( 'includes/class-wcqu-product-unit.php' );
-
- // Add Scripts and styles
+
+ // Add Scripts and styles
add_action( 'wp_enqueue_scripts', array( $this, 'input_value_validation' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'admin_init', array( $this, 'quantity_styles' ) );
-
- // Set WC Version Number
+
+ // Set WC Version Number
add_action( 'init', array( $this, 'get_wc_version' ) );
-
+ add_action( 'init', array( $this, 'text_domain' ) );
+
// Control Admin Notices
// add_action( 'admin_notices', array( $this, 'thumbnail_plugin_notice' ) );
add_action( 'admin_init', array( $this, 'thumbnail_plugin_notice_ignore' ) );
+ add_action( 'admin_init', array( $this, 'text_domain' ) );
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
}
@@ -72,17 +76,21 @@ public function plugins_loaded() {
remove_filter( 'woocommerce_stock_amount', 'intval' );
// allow decimal floats
- add_filter( 'woocommerce_stock_amount', 'floatval' );
+ add_filter( 'woocommerce_stock_amount', 'floatval' );
+ }
+
+ public function text_domain() {
+ load_plugin_textdomain( 'qau', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/*
* Adds default option values
- */
+ */
public function activation_hook() {
$options = get_option( 'ipq_options' );
-
- $defaults = array (
+
+ $defaults = array (
'ipq_site_rule_active' => '',
'ipq_site_min' => '',
'ipq_site_max' => '',
@@ -90,18 +98,18 @@ public function activation_hook() {
'ipq_site_rule_active' => '',
'ipq_show_qty_note' => '',
'ipq_qty_text' => 'Minimum Qty: %MIN%',
- 'ipq_show_qty_note_pos' => 'below',
+ 'ipq_show_qty_note_pos' => 'below',
'ipq_qty_class' => ''
);
// If no options set the defaults
if ( $options == false ) {
add_option( 'ipq_options', $defaults, '', false );
-
+
// Otherwise check that all option are set
} else {
$needs_update = FALSE;
-
+
// Check and assign each unset value
foreach ( $defaults as $key => $value ) {
if ( !isset( $options[$key] ) ) {
@@ -109,7 +117,7 @@ public function activation_hook() {
$needs_update = TRUE;
}
}
-
+
// If values are missing update the options
if ( $needs_update === TRUE ) {
update_option( 'ipq_options', $options );
@@ -121,48 +129,48 @@ public function activation_hook() {
* 'Checks' all user roles for pre-2.1 rules
*
* @status To be depricated in version 2.3
- */
+ */
public function update_rules_with_roles() {
-
+
// Construct default roles list to apply
global $wp_roles;
$roles = $wp_roles->get_names();
$applied_roles = array();
foreach ( $roles as $slug => $name ) {
array_push( $applied_roles, $slug );
- }
-
+ }
+
$args = array (
'posts_per_page' => -1,
'post_type' => 'quantity-rule',
'post_status' => 'publish',
);
-
+
$rules = get_posts( $args );
-
+
// Loop through rules
foreach ( $rules as $rule ) {
- // If their rule value is false, apply all roles
+ // If their rule value is false, apply all roles
$roles = get_post_meta( $rule->ID, '_roles', true );
-
+
if ( $roles == false ) {
update_post_meta( $rule->ID, '_roles', $applied_roles, false );
}
}
}
-
+
/*
* Remove thumbnail plugin notice meta value
- */
+ */
public function deactivation_hook() {
-
+
$args = array(
'meta_key' => 'wpbo_thumbnail_input_notice',
'meta_value' => 'true',
);
-
+
$admins = get_users( $args );
-
+
foreach ( $admins as $admin ) {
delete_user_meta( $admin->ID, 'wpbo_thumbnail_input_notice' );
}
@@ -176,130 +184,131 @@ public function enqueue_styles() {
}
/*
- * Include JS to round any value that isn't a multiple of the
+ * Include JS to round any value that isn't a multiple of the
* step up.
- */
+ */
public function input_value_validation() {
-
+
global $post, $woocommerce;
-
+
// Only display script if we are on a single product or cart page
if ( is_object( $post ) and $post->post_type == 'product' or is_cart() ) {
-
- wp_enqueue_script(
- 'ipq_validation',
+
+ wp_enqueue_script(
+ 'ipq_validation',
plugins_url( '/assets/js/ipq_input_value_validation.js', __FILE__ ),
array( 'jquery' )
);
// Only localize parameters for variable products
if ( ! is_cart() ) {
-
+
// Get the product
$pro = get_product( $post );
-
+
// Check if variable
if ( $pro->product_type == 'variable' ) {
// See what rules are being applied
$rule_result = wcqu_get_applied_rule( $pro );
-
+
// If the rule result is inactive, we're done
if ( $rule_result == 'inactive' or $rule_result == null ) {
return;
-
+
// Get values for Override, Sitewide and Rule Controlled Products
} else {
$values = wcqu_get_value_from_rule( 'all', $pro, $rule_result );
}
-
- // Check if the product is out of stock
+
+ // Check if the product is out of stock
$stock = $pro->get_stock_quantity();
-
+
// Check if the product is under stock management and out of stock
if ( strlen( $stock ) != 0 and $stock <= 0 ) {
-
+
if ( $values['min_oos'] != '' ) {
$values['min_value'] = $values['min_oos'];
}
-
+
if ( $values['max_oos'] != '' ) {
$values['max_value'] = $values['max_oos'];
}
-
+
}
-
+
// Output admin-ajax.php URL with sma eprotocol as current page
$params = array (
'min' => $values['min_value'],
'max' => $values['max_value'],
'step' => $values['step']
- );
-
+ );
+
wp_localize_script( 'ipq_validation', 'ipq_validation', $params );
}
- }
- }
+ }
+ }
}
-
+
/*
* Include Styles
- */
+ */
public function quantity_styles() {
-
+
if ( is_admin() ) {
-
- wp_enqueue_style(
- 'wcqu_admin_quantity_styles',
+
+ wp_enqueue_style(
+ 'wcqu_admin_quantity_styles',
plugins_url( '/assets/css/admin-styles.css', __FILE__ )
);
-
- wp_enqueue_script(
- 'wcqu_admin_script',
+
+ wp_enqueue_script(
+ 'wcqu_admin_script',
plugins_url( '/assets/js/ipq_admin_script.js', __FILE__ ),
array( 'jquery' )
);
}
}
-
+
/*
- * Set what version of WooCommerce the user has installed
- */
+ * Set what version of WooCommerce the user has installed
+ */
public function get_wc_version() {
-
+
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
-
+
$plugin_folder = get_plugins( '/' . 'woocommerce' );
$plugin_file = 'woocommerce.php';
-
+
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
$this->wc_version = $plugin_folder[$plugin_file]['Version'];
} else {
$this->wc_version = NULL;
}
}
-
+
/*
* General Admin Notice to Encourage users to download thumbnail input as well
- */
+ */
public function thumbnail_plugin_notice() {
global $current_user;
- $user_id = $current_user->ID;
+ $user_id = $current_user->ID;
- // Check if Thumbnail Plugin is activated
+ // Check if Thumbnail Plugin is activated
if ( !in_array( 'woocommerce-thumbnail-input-quantities/woocommerce-thumbnail-input-quantity.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
-
+
// Check if User has Dismissed this message already
if ( ! get_user_meta( $user_id, 'wpbo_thumbnail_input_notice' ) ) {
-
- echo '
';
+
+ echo '">'.__("Dismiss Notice",'qau').'
';
}
- }
+ }
}
-
+
/*
* Make Admin Notice Dismissable
- */
+ */
public function thumbnail_plugin_notice_ignore() {
global $current_user;
$user_id = $current_user->ID;
-
+
if ( isset($_GET['wpbo_thumbnail_plugin_dismiss']) && '0' == $_GET['wpbo_thumbnail_plugin_dismiss'] ) {
add_user_meta($user_id, 'wpbo_thumbnail_input_notice', 'true', true);
}