WP Manifestindependent plugin directory
manifest / ecommerce / woocommerce-admin-refund-script-blocker

WooCommerce Admin Refund Script Blocker

Prevents the WooCommerce Account Funds admin refund script and its related Jetpack request from loading on WooCommerce order edit screens.

by Amirreza Shayesteh Far · github.com/amirrezashf/woocommerce-admin-refund-script-blocker · website

★ 0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/amirrezashf/woocommerce-admin-refund-script-blocker/archive/refs/heads/main.zip

Prevent the WooCommerce Account Funds admin refund script and its related Jetpack connection request from loading on WooCommerce order edit screens.

Overview

WooCommerce Admin Refund Script Blocker is a narrowly scoped compatibility plugin for stores where WooCommerce Account Funds loads a problematic refund script on order edit pages.

The targeted script is typically:

woocommerce-account-funds/assets/js/admin/order-refund.min.js

The plugin also blocks the related browser fetch request to:

/wp-json/jetpack/v4/connection/data

Unlike the original snippet, the restriction is not applied across the entire WordPress administration area. It runs only on existing WooCommerce order edit screens.

Features

  • Removes known WooCommerce Account Funds refund-script handles
  • Detects matching scripts by source URL
  • Runs a late cleanup during admin_enqueue_scripts
  • Runs a second cleanup during admin_print_scripts
  • Uses script_loader_tag as a final fallback
  • Supports classic WooCommerce order edit screens
  • Supports WooCommerce HPOS order edit screens
  • Installs the fetch guard early in the document head
  • Supports URL strings and JavaScript Request objects
  • Returns a valid JSON response for blocked requests
  • Does not modify order or refund data
  • Loads no frontend assets
  • Stores no settings or metadata
  • Provides filters for custom handles and source fragments
  • Single-file plugin architecture
  • GPL-3.0

Problem Addressed

Possible symptoms include:

  • JavaScript errors on the order edit screen
  • Failed Jetpack REST API requests
  • Repeated connection-data requests
  • Broken custom refund controls
  • Conflicts with another refund interface
  • Browser console errors
  • Additional admin latency
  • Errors when Jetpack is disconnected

How It Works

The plugin uses three script-removal layers.

Known handle removal

Default handles:

woocommerce-account-funds-admin-order-refund
wc-account-funds-admin-order-refund
account-funds-admin-order-refund

Each matching handle is dequeued and deregistered.

Source URL detection

Queued scripts are inspected for:

woocommerce-account-funds/assets/js/admin/order-refund.min.js
woocommerce-account-funds/assets/js/admin/order-refund.js

This catches changed or unknown handles.

Final output filtering

If a script is enqueued after the cleanup hooks, script_loader_tag prevents the final matching tag from being printed.

Jetpack Fetch Guard

The original code changed window.fetch in admin_footer, which may run too late. This plugin installs the guard in the document head.

It supports:

fetch("https://example.com/wp-json/jetpack/v4/connection/data")

and:

fetch(new Request("https://example.com/wp-json/jetpack/v4/connection/data"))

The blocked request receives a local JSON response with HTTP status 200.

Supported Screens

Classic order storage

wp-admin/post.php?post=123&action=edit

HPOS

wp-admin/admin.php?page=wc-orders&action=edit&id=123

Requirements

  • PHP 7.4+
  • WordPress 6.0+
  • WooCommerce
  • User permission to edit WooCommerce orders

Installation

  1. Download the plugin ZIP file.
  2. Open Plugins → Add New Plugin → Upload Plugin.
  3. Upload the ZIP file.
  4. Install and activate the plugin.
  5. Open an existing WooCommerce order.
  6. Verify the Network and Console panels.

Verification

Confirm that this script is absent:

woocommerce-account-funds/assets/js/admin/order-refund.min.js

Confirm that no network request is sent to:

/wp-json/jetpack/v4/connection/data

Also confirm that:

  • Native WooCommerce refunds still work
  • Required Account Funds controls remain available
  • Order editing is unaffected
  • Other WordPress admin pages are unaffected

Data Storage

The plugin stores no data. It creates no:

  • Options
  • Transients
  • User metadata
  • Order metadata
  • Database tables
  • Scheduled events
  • Log files

Security

  • Direct-file access protection
  • Capability checks
  • Execution limited to existing order edit screens
  • Sanitized request parameters
  • No public AJAX endpoint
  • No REST API route
  • No direct database queries
  • No frontend interception
  • No global Jetpack blocking

Performance

The plugin performs no frontend work. On the order edit screen it only checks a small handle list, inspects queued scripts, and installs one small inline fetch guard.

Filters

wc_arsb_blocked_script_handles

add_filter(
    'wc_arsb_blocked_script_handles',
    static function ( $handles ) {
        $handles[] = 'custom-refund-script';
        return $handles;
    }
);

wc_arsb_blocked_script_fragments

add_filter(
    'wc_arsb_blocked_script_fragments',
    static function ( $fragments ) {
        $fragments[] = 'custom-plugin/assets/order-refund.js';
        return $fragments;
    }
);

wc_arsb_block_jetpack_connection_request

Disable only the fetch guard:

add_filter(
    'wc_arsb_block_jetpack_connection_request',
    '__return_false'
);

Risks and Compatibility Notes

This plugin is a targeted workaround. Removing the script may disable functionality that depends entirely on it.

Before production deployment, test:

  • Native WooCommerce refunds
  • Account Funds refunds
  • Custom refund workflows
  • Refund totals and records
  • Required controls on the order screen

The preferred root-cause solution is to update or fix the source plugin so it loads its assets only when needed.

Limitations

  • The original script is not repaired; it is removed or neutralized.
  • Features implemented exclusively by the blocked script may disappear.
  • Only the configured Jetpack fetch endpoint is intercepted.
  • XMLHttpRequest, jQuery AJAX, and PHP HTTP requests are not intercepted.
  • Other script paths require an additional filter entry.

Changelog

1.0.0

  • Initial release
  • Added known-handle removal
  • Added source URL matching
  • Added late enqueue cleanup
  • Added print-time cleanup
  • Added final script-tag filtering
  • Added early scoped fetch guard
  • Added support for JavaScript Request objects
  • Added valid JSON response
  • Added classic order-screen support
  • Added HPOS support
  • Added public filters

License

GPL-3.0

https://www.gnu.org/licenses/gpl-3.0.html

Author

Amirreza Shayesteh Far


مسدودسازی اسکریپت Refund در مدیریت ووکامرس

جلوگیری از بارگذاری اسکریپت مشکل‌ساز Refund افزونه WooCommerce Account Funds و درخواست مرتبط Jetpack در صفحه ویرایش سفارش ووکامرس.

معرفی

این افزونه یک راهکار سازگاری محدود و هدفمند برای سایت‌هایی است که اسکریپت Refund افزونه WooCommerce Account Funds در صفحه سفارش باعث خطا یا تداخل می‌شود.

مسیر معمول اسکریپت هدف:

woocommerce-account-funds/assets/js/admin/order-refund.min.js

درخواست مرتبط زیر نیز فقط در صفحه ویرایش سفارش مهار می‌شود:

/wp-json/jetpack/v4/connection/data

برخلاف کد اولیه، این محدودیت به کل پنل مدیریت یا frontend اعمال نمی‌شود.

قابلیت‌ها

  • حذف handleهای شناخته‌شده اسکریپت Refund
  • شناسایی اسکریپت بر اساس URL فایل
  • cleanup دیرهنگام در admin_enqueue_scripts
  • cleanup مجدد در admin_print_scripts
  • جلوگیری نهایی از چاپ script tag
  • پشتیبانی از صفحه کلاسیک سفارش
  • پشتیبانی از HPOS
  • نصب زودهنگام محافظ fetch
  • پشتیبانی از URL رشته‌ای و Request
  • پاسخ JSON معتبر برای درخواست مسدودشده
  • بدون تغییر اطلاعات سفارش یا Refund
  • بدون فایل frontend
  • بدون ذخیره تنظیمات یا metadata
  • فیلتر برای handle و مسیرهای سفارشی
  • معماری تک‌فایلی
  • مجوز GPL-3.0

مشکل هدف

نشانه‌های احتمالی:

  • خطای JavaScript در صفحه سفارش
  • درخواست ناموفق Jetpack REST API
  • تکرار درخواست connection data
  • خراب شدن کنترل‌های Refund
  • تداخل با رابط سفارشی Refund
  • خطا در Console
  • کندی پنل مدیریت
  • خطا هنگام قطع بودن Jetpack

نحوه عملکرد

حذف handleهای شناخته‌شده

woocommerce-account-funds-admin-order-refund
wc-account-funds-admin-order-refund
account-funds-admin-order-refund

شناسایی بر اساس URL

woocommerce-account-funds/assets/js/admin/order-refund.min.js
woocommerce-account-funds/assets/js/admin/order-refund.js

جلوگیری نهایی از چاپ

اگر اسکریپت پس از cleanup دوباره enqueue شود، script_loader_tag از چاپ آن جلوگیری می‌کند.

محافظ Fetch مربوط به Jetpack

کد اولیه window.fetch را در admin_footer تغییر می‌داد که ممکن بود دیر اجرا شود. این افزونه محافظ را در head نصب می‌کند.

این حالت‌ها پشتیبانی می‌شوند:

fetch("https://example.com/wp-json/jetpack/v4/connection/data")

و:

fetch(new Request("https://example.com/wp-json/jetpack/v4/connection/data"))

درخواست شبکه ارسال نمی‌شود و پاسخ JSON محلی با وضعیت 200 بازگردانده می‌شود.

صفحه‌های پشتیبانی‌شده

ساختار کلاسیک

wp-admin/post.php?post=123&action=edit

HPOS

wp-admin/admin.php?page=wc-orders&action=edit&id=123

پیش‌نیازها

  • PHP 7.4 یا جدیدتر
  • WordPress 6.0 یا جدیدتر
  • WooCommerce
  • دسترسی ویرایش سفارش‌ها

نصب

  1. فایل ZIP افزونه را دانلود کنید.
  2. وارد افزونه‌ها ← افزودن افزونه تازه ← بارگذاری افزونه شوید.
  3. فایل ZIP را بارگذاری کنید.
  4. افزونه را نصب و فعال کنید.
  5. یک سفارش موجود را باز کنید.
  6. بخش Network و Console را بررسی کنید.

روش بررسی

نباید فایل زیر بارگذاری شود:

woocommerce-account-funds/assets/js/admin/order-refund.min.js

نباید درخواست شبکه به این endpoint ارسال شود:

/wp-json/jetpack/v4/connection/data

همچنین بررسی کنید:

  • Refund استاندارد ووکامرس کار کند
  • کنترل ضروری Account Funds حذف نشده باشد
  • ویرایش سفارش درست کار کند
  • سایر صفحات مدیریت تحت تأثیر نباشند

ذخیره‌سازی داده

افزونه هیچ داده‌ای ذخیره نمی‌کند و موارد زیر را ایجاد نمی‌کند:

  • option
  • transient
  • user meta
  • order meta
  • جدول دیتابیس
  • scheduled event
  • فایل log

امنیت

  • جلوگیری از اجرای مستقیم فایل
  • بررسی capability
  • محدود کردن اجرا به صفحه سفارش موجود
  • پاک‌سازی پارامترهای درخواست
  • بدون AJAX عمومی
  • بدون REST API اختصاصی
  • بدون SQL مستقیم
  • بدون مهار frontend
  • بدون مسدودسازی سراسری Jetpack

عملکرد

در frontend هیچ کاری انجام نمی‌شود. در صفحه سفارش فقط چند handle و URL بررسی می‌شوند و یک محافظ کوچک fetch نصب می‌شود.

فیلترها

wc_arsb_blocked_script_handles

add_filter(
    'wc_arsb_blocked_script_handles',
    static function ( $handles ) {
        $handles[] = 'custom-refund-script';
        return $handles;
    }
);

wc_arsb_blocked_script_fragments

add_filter(
    'wc_arsb_blocked_script_fragments',
    static function ( $fragments ) {
        $fragments[] = 'custom-plugin/assets/order-refund.js';
        return $fragments;
    }
);

wc_arsb_block_jetpack_connection_request

غیرفعال کردن فقط محافظ fetch:

add_filter(
    'wc_arsb_block_jetpack_connection_request',
    '__return_false'
);

ریسک و سازگاری

این افزونه یک workaround هدفمند است. حذف اسکریپت ممکن است قابلیت‌های وابسته به همان فایل را غیرفعال کند.

پیش از استفاده در محیط اصلی، موارد زیر را تست کنید:

  • Refund استاندارد ووکامرس
  • Refund مربوط به Account Funds
  • workflowهای سفارشی Refund
  • مبلغ‌ها و رکوردهای Refund
  • کنترل‌های ضروری صفحه سفارش

راهکار ریشه‌ای بهتر، اصلاح افزونه مبدا است تا فایل خود را فقط در شرایط لازم بارگذاری کند.

محدودیت‌ها

  • اسکریپت اصلی تعمیر نمی‌شود؛ حذف یا خنثی می‌شود.
  • قابلیت‌های وابسته به آن ممکن است حذف شوند.
  • فقط endpoint مشخص‌شده در fetch مهار می‌شود.
  • XMLHttpRequest، jQuery AJAX و درخواست PHP مهار نمی‌شوند.
  • مسیر متفاوت فایل نیازمند filter است.

تاریخچه تغییرات

1.0.0

  • انتشار اولیه
  • حذف handleهای شناخته‌شده
  • شناسایی بر اساس URL
  • cleanup دیرهنگام
  • cleanup هنگام چاپ
  • فیلتر نهایی script tag
  • محافظ fetch زودهنگام
  • پشتیبانی از JavaScript Request
  • پاسخ JSON معتبر
  • پشتیبانی از صفحه کلاسیک
  • پشتیبانی از HPOS
  • افزودن فیلترهای عمومی

مجوز

GPL-3.0

https://www.gnu.org/licenses/gpl-3.0.html

نویسنده

Amirreza Shayesteh Far