Advertisement
Guest User

Untitled

a guest
Jul 30th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. add_action( 'woocommerce_check_cart_items', 'min_amount_of_order' );
  2. // add_action( 'woocommerce_checkout_process', 'min_amount_of_order');
  3. // add_action( 'woocommerce_before_cart' , 'min_amount_of_order');
  4.  
  5. function min_amount_of_order() {
  6.  
  7. if(is_checkout() || is_cart()) {
  8. global $woocommerce;
  9. $minimum = 45; //for state 1
  10. $state = array('BG-23');
  11.  
  12. $cart_total_order = WC()->cart->total;
  13.  
  14. if( $cart_total_order < $minimum && in_array(WC()->customer->get_shipping_state(), $state ) ) {
  15.  
  16. wc_print_notice(
  17. sprintf( 'You must place an order for at least %s in your cart. Your order is currently worth %s' ,
  18. wc_price( $minimum ),
  19. wc_price( WC()->cart->subtotal )
  20. ), 'error'
  21. );
  22. }
  23. }
  24.  
  25. if (is_checkout() || is_cart()){
  26. global $woocommerce;
  27. $minimum = 30; //for state 2
  28. $state = array('BG-22');
  29. $cart_total_order = WC()->cart->total;
  30.  
  31. if( $cart_total_order < $minimum && in_array(WC()->customer->get_shipping_state(), $state )) {
  32.  
  33. wc_print_notice(
  34. sprintf( 'You must place an order for at least %s in your cart. Your order is currently worth %ss' ,
  35. wc_price( $minimum ),
  36. wc_price( WC()->cart->subtotal )
  37. ), 'error'
  38. );
  39. }
  40. }
  41. }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement