Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. /***************************************
  2.  * /Minimumbestellung 6 Stk und glatt teilbar durch Vielfache von 6 (Modolo 0)
  3.  ***************************************/
  4.  
  5. // Set a minimum number of products requirement before checking out
  6. add_action( 'woocommerce_check_cart_items', 'spyr_set_min_num_products' );
  7. function spyr_set_min_num_products() {
  8.     // Only run in the Cart or Checkout pages
  9.     if( is_cart() || is_checkout() ) {
  10.         global $woocommerce;
  11.  
  12.         // Set the minimum number of products before checking out
  13.         $minimum_num_products = 6;
  14.         // Get the Cart's total number of products
  15.         $cart_num_products = WC()->cart->cart_contents_count;
  16.  
  17.         // Compare values and add an error is Cart's total number of products
  18.         // happens to be less than the minimum required before checking out.
  19.         // Will display a message along the lines of
  20.         // A Minimum of 20 products is required before checking out. (Cont. below)
  21.         // Current number of items in the cart: 6  
  22.         if( $cart_num_products < $minimum_num_products || $cart_num_products % 6 != 0) {
  23.             // Display our error message
  24.             wc_add_notice( sprintf( '<strong>Unsere Mindest-Bestellmenge beträgt %s Flaschen. Wir versenden nur Kistenweise, daher muss die Gesamtmenge durch 6 teilbar sein</strong>'
  25.                 . '<br />Aktuelle Artikel im Warenkorb: %s.',
  26.                 $minimum_num_products,
  27.                 $cart_num_products ),
  28.             'error' );
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement