Skip to content

Instantly share code, notes, and snippets.

@dougedgington
Last active December 17, 2015 18:39
Show Gist options
  • Save dougedgington/5654691 to your computer and use it in GitHub Desktop.
Save dougedgington/5654691 to your computer and use it in GitHub Desktop.
Require a minimum order total in Woocommerce for a user role
<?php
/*
Author: Doug Edgington
Description: Require a minimum order total in Woocommerce for a user role
*/
function dee_minimum_order_total_required() {
if( is_user_logged_in() ) {
global $woocommerce;
global $current_user;
get_currentuserinfo();
$dee_user_roles = $current_user->roles;
$dee_user_role = array_shift($dee_user_roles);
$dee_minimum = 50;
if ( $woocommerce->cart->subtotal < $dee_minimum && $dee_user_role == 'wholesale_buyer') {
$woocommerce->add_error( sprintf( 'Wholesale users must have a minimum order total of $%s to place an order.' , $dee_minimum ) );
}
} //end main if statement
}
add_action( 'woocommerce_checkout_process', 'dee_minimum_order_total_required' );
?>
@shyheim
Copy link

shyheim commented Dec 21, 2014

Hi, i tried to put that shortcode on my functions.php but nothing changes.. i also changed 'wholesale_buyer' with my 'wholesale_customer'.. can you help me ? thank you, Luca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment