Change WordPress user roles and capabilities Forums How to or FAQ Restrict Role from Processing Refunds in WooCommerce Reply To: Restrict Role from Processing Refunds in WooCommerce

#2732
Vladimir
Keymaster

Thanks for the clarification. I missed ‘Order status’ field yesterday. Try this version. It removes dropdown list of statuses if order was refunded already and just shows “Refunded” text and removes ‘Refunded’ item from the dropdown list options in other cases:


add_action('admin_head', 'hide_wc_refund_button');

function hide_wc_refund_button() {

    global $post;

    if (!current_user_can('sales')) {
        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

}