Function.php   https://app.screencast.com/5pVbjFQEV7y85

 

function filter_woocommerce_package_rates( $rates, $package ) {
// Set the rate IDs in the array
$rate_usps_free = array( ‘free_shipping:3’, ‘free_shipping’, ‘usps’, ‘usps:1:flat_rate_box_priority’, ‘usps:1:D_FIRST_CLASS’, ‘usps:1:D_PRIORITY_MAIL’, ‘usps:1:D_EXPRESS_MAIL’, ‘usps:1:D_GROUND_ADVANTAGE’ );
$rate_flat = array(‘flat_rate:9’, ‘flat_rate’);
$rate_usps_flat = array( ‘flat_rate:9’, ‘flat_rate’, ‘usps’, ‘usps:1:flat_rate_box_priority’, ‘usps:1:D_FIRST_CLASS’, ‘usps:1:D_PRIORITY_MAIL’, ‘usps:1:D_EXPRESS_MAIL’, ‘usps:1:D_GROUND_ADVANTAGE’ );
// Set minimum order amount
$minimum = 250;

// Get cart total
$cart_total = WC()->cart->total;

// NOT the required user role, remove shipping method(s)
if ( current_user_can( ‘poa’ ) && $cart_total < $minimum ) {
// Loop trough
foreach ( $rates as $rate_id => $rate ) {
// Checks if a value exists in an array
if ( in_array( $rate_id, $rate_usps_free ) ) {
unset( $rates[$rate_id] );
}
}
} elseif ( ! current_user_can( ‘poa’ ) ) {
foreach ( $rates as $rate_id => $rate ) {
// Checks if a value exists in an array
if ( in_array( $rate_id, $rate_flat ) ) {
unset( $rates[$rate_id] );
}
}
} elseif ( current_user_can( ‘poa’ ) && $cart_total > $minimum ) {
foreach ( $rates as $rate_id => $rate ) {
// Checks if a value exists in an array
if ( in_array( $rate_id, $rate_usps_flat ) ) {
unset( $rates[$rate_id] );
}
}
}

return $rates;
}
add_filter( ‘woocommerce_package_rates’, ‘filter_woocommerce_package_rates’, 10, 2 );

Leave a Reply

Are you over 21?

We use cookies to provide and improve our services. By using our site, you consent to cookies.
< Back
There are no products in your cart.
Product total: $0.00
Pay now
0
0 items in your cart - $0.00
Pay now