Skip to content

Instantly share code, notes, and snippets.

@kloon
Created June 21, 2013 13:28
Show Gist options
  • Save kloon/5831114 to your computer and use it in GitHub Desktop.
Save kloon/5831114 to your computer and use it in GitHub Desktop.

Revisions

  1. kloon created this gist Jun 21, 2013.
    18 changes: 18 additions & 0 deletions WooCommerce_free_shipping_user_role.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?php
    function get_user_role() {
    global $current_user;

    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);

    return $user_role;
    }

    add_filter( 'woocommerce_available_shipping_methods', 'woocommerce_unset_free_shipping_for_certain_users' );
    function woocommerce_unset_free_shipping_for_certain_users( $methods ) {
    $user_role = get_user_role();
    if ( $user_role != 'administrator' )
    unset( $methods['free_shipping'] );
    return $methods;
    }
    ?>