Conflict: Wallet plugin’s DataTables v1 JS causes errors with other plugins
-
We’ve identified a JavaScript conflict between the Wallet System for WooCommerce plugin and other plugins that rely on DataTables v2 (ES modules), such as Uncanny Owl’s Tin Canny student report page.
When the Wallet plugin is active, the following error occurs on the Tin Canny student report page:
Uncaught TypeError: Cannot read properties of undefined (reading '0') at At (dataTables.mjs:8676:16) ...After investigation, the cause is clear:
- Wallet enqueues DataTables v1 (jQuery build) JS globally:
wp_enqueue_script( 'wps-datatable', WALLET_SYSTEM_FOR_WOOCOMMERCE_DIR_URL . 'package/lib/datatables/media/js/jquery.dataTables.min.js', array(), $this->version, true ); - This is loaded unconditionally on all frontend pages, even where the Wallet plugin is not being used.
- Meanwhile, Tin Canny (and likely other modern plugins) use DataTables v2. Having both versions loaded breaks the Responsive extension and table initialization.
Steps to reproduce:
- Install and activate Wallet System for WooCommerce and Tin Canny.
- Visit the Tin Canny student report page.
- Observe the JavaScript error and broken DataTable rendering.
Workaround:
We’ve temporarily resolved the issue by dequeuingwps-datatableon the Tin Canny report page with awp_dequeue_scripthook, but this is not an ideal solution.Requested Fix:
Please scope your DataTables assets properly so they only load where Wallet tables are rendered:- Restrict enqueue of DataTables v1 JS & CSS
Only enqueue on wallet endpoints, similar to how your CSS is already scoped:$is_endpoint = isset($wp_query->query_vars['wps-wallet']) ? $wp_query->query_vars['wps-wallet'] : ''; if ( is_account_page() && in_array($is_endpoint, ['wallet-transactions','wallet-withdrawal'], true) ) { wp_enqueue_style('wps-datatable', ...); wp_enqueue_script( 'wps-datatable', WALLET_SYSTEM_FOR_WOOCOMMERCE_DIR_URL . 'package/lib/datatables/media/js/jquery.dataTables.min.js', array('jquery'), $this->version, true ); } - Fix dependency declarations
Add'jquery'as a dependency for the DataTables script to ensure it loads after jQuery. - Correct
wp_enqueue_scriptargument usage
Currentlywp_enqueue_script( 'wps-public-min', ..., 'all')uses'all'where a boolean$in_footeris expected. This should betrueorfalse. - Scope DataTables initialization
In your JS, avoid selecting$('table.dataTable')globally. Instead, initialize only the tables inside your wallet template DOM container (e.g.,$('#wps-wallet table.wps-datatable')).
Why this matters:
Without these changes, the Wallet plugin can break any other plugin/theme that also relies on DataTables (especially v2). Scoping your assets ensures compatibility and prevents site-wide JavaScript conflicts. - Wallet enqueues DataTables v1 (jQuery build) JS globally:
You must be logged in to reply to this topic.