Skip to content

Instantly share code, notes, and snippets.

@wpflames
Last active April 8, 2022 13:15
Show Gist options
  • Select an option

  • Save wpflames/2c26fe7032f1d893e226eef05da16f89 to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/2c26fe7032f1d893e226eef05da16f89 to your computer and use it in GitHub Desktop.
Hide Free Shipping Notice of Current User is WholeSale Customer
<?php
// =========================================================================
// Hide Free Shipping Notice of Current User is WholeSale Customer
// =========================================================================
function free_shipping_cart_notification() {
$wholesaler = false;
// Get current user role
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
// If current user is a wholesaler set the boolean to true
if($user_role === 'wholesale_customer'){
$wholesaler = true;
}
// Specify the minimum order amount
$min_amount = 100; //change this to your free shipping threshold
$current = WC()->cart->subtotal;
// If not wholesaler and the order total is less than the treshold display the message
if(!$wholesaler && $current < $min_amount){
$added_text = 'Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!';
$return_to = wc_get_page_permalink( 'shop' );
$notice = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), 'Continue Shopping', $added_text );
wc_print_notice( $notice, 'notice' );
}
}
add_action( 'woocommerce_before_cart', 'free_shipping_cart_notification' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment