Skip to content

Instantly share code, notes, and snippets.

@dougedgington
Created May 27, 2013 01:43
Show Gist options
  • Save dougedgington/5654773 to your computer and use it in GitHub Desktop.
Save dougedgington/5654773 to your computer and use it in GitHub Desktop.
Shortcode to display a minimum order total required message to users in a specific user role on checkout page when using Woocommerce
<?php
/*
Author: Doug Edgington
Description: Shortcode to display a minimum order total required message to
users in a specific user role on checkout page when using Woocommerce
*/
function dee_minimum_order_total_message() {
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') {
return( sprintf( '<span class="min-wholesale-message">Wholesale users must have a minimum order total of $%s to place an order.</span>' , $dee_minimum ) );
}
} //end main if statement
}
add_shortcode('minimum-required', 'dee_minimum_order_total_message');
?>
@daveetasac
Copy link

Thank you so much for this, Doug! This is exactly what I was looking for! I have one question:

I sell bottles and cases of salsa, and want to restrict Wholesale Buyers from purchasing individual bottles. Would it be possible for you to show me how to check if a bottle (by variation ID) is in the cart, and if its a Wholesale Buyer, to display an error message stating they can only purchase cases? Thanks again!

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