wcpgsk_after_cart_item_quantity_update

The Woocommerce Poor Guys Swiss Knife wcpgsk after cart item quantity update function.

Description

wcpgsk_after_cart_item_quantity_update( $cart_item_key, $quantity ); 

Parameters (2)

0. $cart_item_key
The cart item key.
1. $quantity
The quantity.

Usage

  1. if ( !function_exists( 'wcpgsk_after_cart_item_quantity_update' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-poor-guys-swiss-knife/wcpgsk-af.php'; 
  3.  
  4. // The cart item key. 
  5. $cart_item_key = null; 
  6.  
  7. // The quantity. 
  8. $quantity = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wcpgsk_after_cart_item_quantity_update($cart_item_key, $quantity); 
  12.  

Defined (1)

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

/wcpgsk-af.php  
  1. function wcpgsk_after_cart_item_quantity_update( $cart_item_key, $quantity ) { 
  2. global $woocommerce; 
  3. $options = get_option( 'wcpgsk_settings' ); 
  4. $product_id = $woocommerce->cart->cart_contents[$cart_item_key]['product_id']; 
  5. $variation_id = $woocommerce->cart->cart_contents[$cart_item_key]['variation_id']; 
  6. $product = get_product($product_id); 
  7.  
  8. $maxqty = isset($options['cart']['maxqty_' . $product->product_type]) ? $options['cart']['maxqty_' . $product->product_type] : 0; 
  9. $minqty = isset($options['cart']['minqty_' . $product->product_type]) ? $options['cart']['minqty_' . $product->product_type] : 0; 
  10. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  11. $product_id = $product->ID;  
  12. $maxval = get_post_meta($product_id, '_wcpgsk_maxqty', true); 
  13. $minval = get_post_meta($product_id, '_wcpgsk_minqty', true); 
  14. if ( isset($maxval) && $maxval > 0 ) : 
  15. $maxqty = $maxval; 
  16. endif; 
  17. if ( isset($minval) && $minval > 0 ) : 
  18. $minqty = $minval; 
  19. endif; 
  20. endif; 
  21.  
  22.  
  23. if ($minqty > 0 && $quantity < $minqty) : 
  24. $woocommerce->cart->cart_contents[$cart_item_key]['quantity'] = $minqty; 
  25. wcpgsk_add_message( sprintf( __( 'You have to buy a minimum quantity. We have set the required minimum of %s as quantity for you.', WCPGSK_DOMAIN ), $minqty ) ); 
  26.  
  27. elseif ($maxqty > 0 && $quantity > $maxqty) : 
  28. $woocommerce->cart->cart_contents[$cart_item_key]['quantity'] = $maxqty; 
  29. wcpgsk_add_message( sprintf(__( 'You cannot buy more than the allowed maximum quantity. We have set the allowed maximum of %s as quantity for you.', WCPGSK_DOMAIN ), $maxqty ) ); 
  30. endif;