How to Control Permissions for WooCommerce Refunds

WooCommerce has permissions for many different features. For example, in another post, we saw how to control who edits orders in WooCommerce.

However, not all WooCommerce features have permissions. One PublishPress user wanted to control who can process refunds. This is possible with a little custom code.

How to hide the Refund options

We will need to hide two features in WoCommerce.

First, we need to hide the “Refund” button. You can see the “Refund” button by going to WooCommerce > Orders and editing an existing order. You can see the button in the image below:

Second, we need to hide the “Refunded” option that is under the “Status” dropdown. You can see this in the image below:

How to block users from refunds

So if you want to block some users from processing refunds, what do you do? The answer is here on the WordPress forums. The solution is to hide the “Refund” button for some users.

You can add this code directly to the functions.php file in your theme. So if you’re using the Twenty Nineteen theme, your code will go into /wp-content/themes/twentynineteen/functions.php.

add_action('admin_head', 'hide_wc_refund_button');

function hide_wc_refund_button() {

    global $post;

   if (!current_user_can('administrator') && !current_user_can('editor')) {
    return;
}
    if (strpos($_SERVER['REQUEST_URI'], 'post.php?post=') === false) {
        return;
    }

    if (empty($post) || $post->post_type != 'shop_order') {
        return;
    }
?>
    <script>
      jQuery(function () {
            jQuery('.refund-items').hide();
            jQuery('.order_actions option[value=send_email_customer_refunded_order]').remove();
            if (jQuery('#original_post_status').val()=='wc-refunded') {
                jQuery('#s2id_order_status').html('Refunded');
            } else {
                jQuery('#order_status option[value=wc-refunded]').remove();
            }
        });
    </script>
    <?php

}

You will need to replace the fourth line with user roles that you DO NOT want processing refunds. In this example, I’ve entered two roles: “administrator” and “editor”.

Once this code is in place, people in the user roles you entered will not see the “Refund” button. The “Refunded” option will also be hidden in the “Status” dropdown.

Leave a Reply

Your email address will not be published. Required fields are marked *

Professional publishing plugins for WordPress! Get PublishPress

[i]
[i]