Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Validate cart items against set rules
- *
- * @throws Exception When cart validation fails.
- */
- public function check_cart_items() {
- try {
- $checked_ids = array();
- $product_quantities = array();
- $category_quantities = array();
- $total_quantity = 0;
- $total_cost = 0;
- $apply_cart_rules = false;
- /**
- * Use this filter to include/exclude tax when calculating total cost of the cart.
- *
- * @since 5.1.0
- *
- * @param boolean $include_tax Include tax.
- */
- $include_tax = apply_filters( 'wc_min_max_quantity_include_tax_order_value_restrictions', true );
- $price_fn = $include_tax ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
- // Count items + variations first.
- foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
- do_action( 'woocommerce/cart_loop/start', $values );
- $product = $values['data'];
- $checking_id = $this->get_id_to_check( $values );
- /**
- * Use this filter to prevent the quantity of a cart item from being counted in cart-level rules.
- *
- * @since 2.4.11
- *
- * @param boolean $do_not_count
- * @param int $checking_id
- * @param string $cart_item_key
- * @param array $values
- */
- if ( apply_filters( 'wc_min_max_cart_quantity_do_not_count', false, $checking_id, $cart_item_key, $values ) ) {
- $values['quantity'] = 0;
- }
- if ( ! isset( $product_quantities[ $checking_id ] ) ) {
- $product_quantities[ $checking_id ] = $values['quantity'];
- } else {
- $product_quantities[ $checking_id ] += $values['quantity'];
- }
- $checking_product = wc_get_product( $checking_id );
- $parent_product = $values['product_id'] === $checking_id ? $checking_product : wc_get_product( $values['product_id'] );
- $minmax_do_not_count = 'no';
- if ( $checking_product && 'yes' === $checking_product->get_meta( 'variation_minmax_do_not_count', true ) ) {
- $minmax_do_not_count = 'yes';
- } elseif ( $parent_product && 'yes' === $parent_product->get_meta( 'minmax_do_not_count', true ) ) {
- $minmax_do_not_count = 'yes';
- }
- /**
- * Use this filter to prevent the quantity or cost of a cart item from being counted in cart-level rules.
- *
- * @since 2.3.6
- *
- * @param boolean $do_not_count
- * @param int $checking_id
- * @param string $cart_item_key
- * @param array $values
- */
- $minmax_do_not_count = apply_filters( 'wc_min_max_quantity_minmax_do_not_count', $minmax_do_not_count, $checking_id, $cart_item_key, $values );
- $minmax_cart_exclude = 'no';
- if ( $checking_product && 'yes' === $checking_product->get_meta( 'variation_minmax_cart_exclude', true ) ) {
- $minmax_cart_exclude = 'yes';
- } elseif ( $parent_product && 'yes' === $parent_product->get_meta( 'minmax_cart_exclude', true ) ) {
- $minmax_cart_exclude = 'yes';
- }
- /**
- * Use this filter to exclude a product from cart-level rules.
- *
- * @since 2.3.6
- *
- * @param boolean $exclude
- * @param int $checking_id
- * @param string $cart_item_key
- * @param array $values
- */
- $minmax_cart_exclude = apply_filters( 'wc_min_max_quantity_minmax_cart_exclude', $minmax_cart_exclude, $checking_id, $cart_item_key, $values );
- if ( 'yes' !== $minmax_do_not_count && 'yes' !== $minmax_cart_exclude ) {
- $total_cost += $price_fn(
- $product,
- array(
- 'price' => (float) $product->get_price(),
- 'qty' => (float) $values['quantity'],
- )
- );
- }
- do_action( 'woocommerce/cart_loop/end', $values );
- }
- // Check cart items.
- foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
- do_action( 'woocommerce/cart_loop/start', $values );
- $checking_id = $this->get_id_to_check( $values );
- $terms = get_the_terms( $values['product_id'], 'product_cat' );
- $found_term_ids = array();
- // If a product belongs to multiple categories with different 'Group of' values, find the category with the smallest 'Group of' value.
- $min_group_of_category_id = 0;
- $min_group_of_category_value = 0;
- $checking_product = wc_get_product( $checking_id );
- $parent_product = $values['product_id'] === $checking_id ? $checking_product : wc_get_product( $values['product_id'] );
- if ( $terms ) {
- foreach ( $terms as $term ) {
- if ( in_array( $term->term_id, $found_term_ids, true ) ) {
- continue;
- }
- if ( ( $checking_product && 'yes' === $checking_product->get_meta( 'variation_minmax_category_group_of_exclude', true ) ) || ( $parent_product && 'yes' === $parent_product->get_meta( 'minmax_category_group_of_exclude', true ) ) ) {
- continue;
- }
- if ( ( ! $checking_product || ! empty( $checking_product->get_meta( 'variation_group_of_quantity', true ) ) ) || ( ! $parent_product || ! empty( $parent_product->get_meta( 'group_of_quantity', true ) ) ) ) {
- continue;
- }
- $found_term_ids[] = $term->term_id;
- $category_group_of_value = absint( get_term_meta( $term->term_id, 'group_of_quantity', true ) );
- if ( 0 !== $category_group_of_value && ( 0 === $min_group_of_category_value || $category_group_of_value < $min_group_of_category_value ) ) {
- $min_group_of_category_value = $category_group_of_value;
- $min_group_of_category_id = $term->term_id;
- }
- // Record count in parents of this category too.
- $parents = get_ancestors( $term->term_id, 'product_cat' );
- foreach ( $parents as $parent ) {
- if ( in_array( $parent, $found_term_ids, true ) ) {
- continue;
- }
- $found_term_ids[] = $parent;
- $category_group_of_value = absint( get_term_meta( $parent, 'group_of_quantity', true ) );
- if ( 0 !== $category_group_of_value && ( 0 === $min_group_of_category_value || $category_group_of_value < $min_group_of_category_value ) ) {
- $min_group_of_category_value = $category_group_of_value;
- $min_group_of_category_id = $parent;
- }
- }
- }
- }
- if ( 0 !== $min_group_of_category_id && 0 !== $min_group_of_category_value ) {
- $category_quantities[ $min_group_of_category_id ] = isset( $category_quantities[ $min_group_of_category_id ] )
- ? $category_quantities[ $min_group_of_category_id ] + $values['quantity']
- : $values['quantity'];
- }
- // Check item rules once per product ID.
- if ( in_array( $checking_id, $checked_ids, true ) ) {
- continue;
- }
- $product = $values['data'];
- $minmax_do_not_count = 'no';
- if ( $checking_product && 'yes' === $checking_product->get_meta( 'variation_minmax_do_not_count', true ) ) {
- $minmax_do_not_count = 'yes';
- } elseif ( $parent_product && 'yes' === $parent_product->get_meta( 'minmax_do_not_count', true ) ) {
- $minmax_do_not_count = 'yes';
- }
- /**
- * Use this filter to prevent the quantity or cost of a cart item from being counted in cart-level rules.
- *
- * @since 2.3.6
- *
- * @param boolean $do_not_count
- * @param int $checking_id
- * @param string $cart_item_key
- * @param array $values
- */
- $minmax_do_not_count = apply_filters( 'wc_min_max_quantity_minmax_do_not_count', $minmax_do_not_count, $checking_id, $cart_item_key, $values );
- $minmax_cart_exclude = 'no';
- if ( $checking_product && 'yes' === $checking_product->get_meta( 'variation_minmax_cart_exclude', true ) ) {
- $minmax_cart_exclude = 'yes';
- } elseif ( $parent_product && 'yes' === $parent_product->get_meta( 'minmax_cart_exclude', true ) ) {
- $minmax_cart_exclude = 'yes';
- }
- /**
- * Use this filter to exclude a product from cart-level rules.
- *
- * @since 2.3.6
- *
- * @param boolean $exclude
- * @param int $checking_id
- * @param string $cart_item_key
- * @param array $values
- */
- $minmax_cart_exclude = apply_filters( 'wc_min_max_quantity_minmax_cart_exclude', $minmax_cart_exclude, $checking_id, $cart_item_key, $values );
- if ( 'yes' === $minmax_do_not_count || 'yes' === $minmax_cart_exclude ) {
- // Do not count.
- $this->excludes[] = $product->get_name();
- } else {
- $total_quantity += $product_quantities[ $checking_id ];
- }
- if ( 'yes' !== $minmax_cart_exclude ) {
- $apply_cart_rules = true;
- }
- $checked_ids[] = $checking_id;
- if ( $values['variation_id'] ) {
- $variation = wc_get_product( $values['variation_id'] );
- $min_max_rules = $variation ? 'yes' === $variation->get_meta( 'min_max_rules', true ) : false;
- $allow_combination = $parent_product ? 'yes' === $parent_product->get_meta( 'allow_combination', true ) : false;
- [
- WC_Min_Max_Quantities_Quantity_Rules::MINIMUM => $minimum_quantity,
- WC_Min_Max_Quantities_Quantity_Rules::MAXIMUM => $maximum_quantity,
- WC_Min_Max_Quantities_Quantity_Rules::GROUP_OF => $group_of_quantity
- ] = $this->get_quantity_rules_for_product( $values['variation_id'] );
- $filter_id = $min_max_rules && ! $allow_combination ? $values['variation_id'] : $values['product_id'];
- } else { // Not a variable product.
- [
- WC_Min_Max_Quantities_Quantity_Rules::MINIMUM => $minimum_quantity,
- WC_Min_Max_Quantities_Quantity_Rules::MAXIMUM => $maximum_quantity,
- WC_Min_Max_Quantities_Quantity_Rules::GROUP_OF => $group_of_quantity
- ] = $this->get_quantity_rules_for_product( $checking_id );
- $filter_id = $checking_id;
- }
- /**
- * Use this filter to filter the Minimum Quantity of a product/variation.
- *
- * @since 2.2.7
- *
- * @param string $quantity
- * @param int $product_id
- * @param string $cart_item_key
- * @param array $cart_item
- */
- $minimum_quantity = absint( apply_filters( 'wc_min_max_quantity_minimum_allowed_quantity', $minimum_quantity, $filter_id, $cart_item_key, $values ) );
- /**
- * Use this filter to filter the Maximum Quantity of a product/variation.
- *
- * @since 2.2.7
- *
- * @param string $quantity
- * @param int $product_id
- * @param string $cart_item_key
- * @param array $cart_item
- */
- $maximum_quantity = absint( apply_filters( 'wc_min_max_quantity_maximum_allowed_quantity', $maximum_quantity, $filter_id, $cart_item_key, $values ) );
- /**
- * Use this filter to filter the Group of quantity of a product/variation.
- *
- * @since 2.2.7
- *
- * @param string $quantity
- * @param int $product_id
- * @param string $cart_item_key
- * @param array $cart_item
- */
- $group_of_quantity = absint( apply_filters( 'wc_min_max_quantity_group_of_quantity', $group_of_quantity, $filter_id, $cart_item_key, $values ) );
- $this->check_rules( $product, $product_quantities[ $checking_id ], $minimum_quantity, $maximum_quantity, $group_of_quantity, $checking_id );
- do_action( 'woocommerce/cart_loop/end', $values );
- }
- // Cart rules.
- if ( $apply_cart_rules ) {
- $excludes = '';
- if ( count( $this->excludes ) > 0 ) {
- $excludes = ' (' . __( 'excludes ', 'woocommerce-min-max-quantities' ) . implode( ', ', $this->excludes ) . ')';
- }
- if ( $this->minimum_order_quantity > 0 && $total_quantity < $this->minimum_order_quantity ) {
- /* translators: %d: Minimum amount of items in the cart */
- $notice = sprintf( __( 'To place an order, your cart must contain at least %d items.', 'woocommerce-min-max-quantities' ), $this->minimum_order_quantity ) . $excludes;
- throw new Exception( $notice );
- }
- if ( $this->maximum_order_quantity > 0 && $total_quantity > $this->maximum_order_quantity ) {
- /* translators: %d: Maximum amount of items in the cart */
- $notice = sprintf( __( 'Your cart must not contain more than %d items to place an order.', 'woocommerce-min-max-quantities' ), $this->maximum_order_quantity );
- throw new Exception( $notice );
- }
- // Check cart value.
- if ( $this->minimum_order_value && $total_cost < $this->minimum_order_value ) {
- /* translators: %s: Minimum order value */
- $notice = sprintf( __( 'To place an order, your cart total must be at least %s.', 'woocommerce-min-max-quantities' ), wc_price( $this->minimum_order_value ) ) . $excludes;
- throw new Exception( $notice );
- }
- if ( $this->maximum_order_value && $total_cost > $this->maximum_order_value ) {
- /* translators: %s: Maximum order value */
- $notice = sprintf( __( 'Your cart total must not be higher than %s to place an order.', 'woocommerce-min-max-quantities' ), wc_price( $this->maximum_order_value ) );
- throw new Exception( $notice );
- }
- }
- // Check category rules.
- foreach ( $category_quantities as $category => $quantity ) {
- $group_of_quantity = get_term_meta( $category, 'group_of_quantity', true );
- if ( $group_of_quantity > 0 && ( intval( $quantity ) % intval( $group_of_quantity ) > 0 ) ) {
- $term = get_term_by( 'id', $category, 'product_cat' );
- $product_names = array();
- foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
- // If exclude is enable, skip.
- if ( ( $parent_product && 'yes' === $parent_product->get_meta( 'minmax_category_group_of_exclude', true ) ) || ( $variation && 'yes' === $variation->get_meta( 'variation_minmax_category_group_of_exclude', true ) ) ) {
- continue;
- }
- if ( has_term( $category, 'product_cat', $values['product_id'] ) ) {
- $product_names[] = $values['data']->get_title();
- }
- }
- if ( $product_names ) {
- /* translators: %1$s: Category name, %2$s: Comma separated list of product names, %3$d: Group amount */
- $notice = sprintf( __( 'Products in the <strong>%1$s</strong> category (<em>%2$s</em>) must be bought in multiples of %3$d.', 'woocommerce-min-max-quantities' ), $term->name, implode( ', ', $product_names ), $group_of_quantity, $group_of_quantity - ( $quantity % $group_of_quantity ) );
- throw new Exception( $notice );
- }
- }
- }
- } catch ( Exception $e ) {
- if ( WC_MMQ_Core_Compatibility::is_store_api_request() ) {
- throw $e;
- } else {
- $notice = $e->getMessage();
- if ( $notice ) {
- wc_add_notice( $notice, 'error' );
- }
- }
- }
- }
Advertisement
Comments
-
- woocommerce-min-max-quantities/woocommerce-min-max-quantities.php
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=eftcgrtnbm
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment