Advertisement
Guest User

woocom_min_order

a guest
Nov 3rd, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
  2. function spyr_set_min_total() {
  3.     // Only run in the Cart or Checkout pages
  4.     if( is_cart() || is_checkout() ) {
  5.         global $woocommerce;
  6.         global $product;
  7.  
  8.         // get user attributes
  9.         $current_user = wp_get_current_user();
  10.  
  11.         // Set minimum cart total
  12.         if ( wc_customer_bought_product( $current_user->email, $current_user->ID ) ) {
  13.             $minimum_cart_total = 300;
  14.         } else {
  15.             $minimum_cart_total = 100;
  16.         }
  17.         // $minimum_cart_total = 100;
  18.  
  19.         // Total we are going to be using for the Math
  20.         // This is before taxes and shipping charges
  21.         $total = WC()->cart->subtotal;
  22.          
  23.         // Compare values and add an error is Cart's total
  24.         // happens to be less than the minimum required before checking out.
  25.         // Will display a message along the lines of
  26.         // A Minimum of 10 USD is required before checking out. (Cont. below)
  27.         // Current cart total: 6 USD
  28.         if( $total <= $minimum_cart_total  ) {
  29.             // Display our error message
  30.             wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
  31.                 .'<br />Current cart\'s total: %s %s',
  32.                 $minimum_cart_total,
  33.                 get_option( 'woocommerce_currency'),
  34.                 $total,
  35.                 get_option( 'woocommerce_currency') ),
  36.             'error' );
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement