Last active
December 17, 2015 18:39
-
-
Save dougedgington/5654691 to your computer and use it in GitHub Desktop.
Require a minimum order total in Woocommerce for a user role
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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