wcpgsk_globalqty_cart_add

The Woocommerce Poor Guys Swiss Knife wcpgsk globalqty cart add function.

Description

wcpgsk_globalqty_cart_add( $valid, $product_id, $quantity ); 

Parameters (3)

0. $valid
The valid.
1. $product_id
The product id.
2. $quantity
The quantity.

Usage

  1. if ( !function_exists( 'wcpgsk_globalqty_cart_add' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-poor-guys-swiss-knife/wcpgsk-af.php'; 
  3.  
  4. // The valid. 
  5. $valid = null; 
  6.  
  7. // The product id. 
  8. $product_id = null; 
  9.  
  10. // The quantity. 
  11. $quantity = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wcpgsk_globalqty_cart_add($valid, $product_id, $quantity); 
  15.  

Defined (1)

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

/wcpgsk-af.php  
  1. function wcpgsk_globalqty_cart_add( $valid, $product_id, $quantity ) {  
  2. global $woocommerce; 
  3. //if ( !is_product() ) : 
  4. $options = get_option( 'wcpgsk_settings' ); 
  5. $maxqtycart = isset( $options['cart']['maxqtycart'] ) ? $options['cart']['maxqtycart'] : 0; 
  6. $minqtycart = isset( $options['cart']['minqtycart'] ) ? $options['cart']['minqtycart'] : 0; 
  7. $qtycnt = 0; 
  8. $prodcnt = 0; 
  9. foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) : 
  10. $qtycnt += $values['quantity']; 
  11. $prodcnt++; 
  12. endforeach; 
  13. $qtycnt += $quantity; 
  14. if ( $maxqtycart && is_numeric($maxqtycart) && $qtycnt > $maxqtycart ) :  
  15. wcpgsk_add_message( sprintf( __( 'The overall sum for all product quantities is restricted to %s in this shop. Your overall quantity sum: %s. Please buy less quantity at least for some products.', WCPGSK_DOMAIN ), $maxqtycart, $qtycnt ) ); 
  16. endif; 
  17. if ( $minqtycart && is_numeric($minqtycart) && $qtycnt < $minqtycart ) :  
  18. wcpgsk_add_message( sprintf( __( 'The required minimum sum for all product quantities is set to %s in this shop. Your overall quantity sum: %s. You have to add products to your cart or buy existing products in a higher quantity.', WCPGSK_DOMAIN ), $minqtycart, $qtycnt ) ); 
  19. endif; 
  20. //endif; 
  21. return $valid;