# Require a Reason Before Issuing a Refund

> Stops staff from issuing a refund in the order screen until they have typed a reason, so every refund in your records is explained.

- Type: PHP
- Runs: Admin only
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, refunds, admin, orders
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-refund-reason-required/

## Code

```php
add_action( 'admin_footer', function () {
    $screen = get_current_screen();

    if ( ! $screen || ! function_exists( 'wc_get_page_screen_id' ) || wc_get_page_screen_id( 'shop-order' ) !== $screen->id ) {
        return;
    }
    ?>
    <script>
    document.addEventListener( 'click', function ( event ) {
        var button = event.target.closest( '.do-api-refund, .do-manual-refund' );
        var reason = document.getElementById( 'refund_reason' );
        if ( ! button || ! reason || reason.value.trim() !== '' ) { return; }
        event.preventDefault();
        event.stopImmediatePropagation();
        window.alert( <?php echo wp_json_encode( 'Please enter a reason for this refund first.' ); ?> );
        reason.focus();
    }, true );
    </script>
    <?php
} );
```

## Notes

Works with both manual and gateway (API) refunds on HPOS and legacy order screens.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a Reason Before Issuing a Refund" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
