Link to home
Start Free TrialLog in
Avatar of Andrew Spackman
Andrew Spackman

asked on

Overriding plugin js file using wp_dequeue_script

Hi,
I need to make some changes to a plugins js file and I want to do it so that it's not overwritten on any plugin updates

The file I am trying to override is  wp_enqueue_script( 'dokan-script' );

// store and my account page
        if ( dokan_is_store_page() || dokan_is_store_review_page() || is_account_page() || is_product() ) {

            if ( DOKAN_LOAD_STYLE ) {
                wp_enqueue_style( 'dokan-select2-css' );
            }

            if ( DOKAN_LOAD_SCRIPTS ) {

                self::load_form_validate_script();
                $this->load_gmap_script();

                wp_enqueue_script( 'jquery-ui-sortable' );
                wp_enqueue_script( 'jquery-ui-datepicker' );
                wp_enqueue_script( 'dokan-tooltip' );
                wp_enqueue_script( 'dokan-chosen' );
                wp_enqueue_script( 'dokan-form-validate' );
                wp_enqueue_script( 'speaking-url' );
                wp_enqueue_script( 'dokan-vendor-registration' );
                wp_enqueue_script( 'dokan-script' );
                wp_enqueue_script( 'dokan-select2-js' );
            }
        }

        do_action( 'dokan_enqueue_scripts' );
    }

Open in new window


Then further down in that file its calling the dokan.js file I want to override...

'dokan-script' => array(
                'src'       => $asset_url . '/js/dokan.js',
                'deps'      => array( 'imgareaselect', 'customize-base', 'customize-model', 'dokan-i18n-jed' ),
                'version'   => filemtime( $asset_path . '/js/dokan.js' ),
            ),

Open in new window


Can someone help me as I'm not sure where to start or where to place my code?

Many Thanks,

Andrew
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

In your functions.php file dequeue the script and enqueue your new script

function replace_scripts() {
    wp_dequeue_script( 'dokan-script' );
    wp_deregister_script( 'dokan-script' );
    // Enqueue your new script here
}
add_action( 'wp_print_scripts', 'replace_scripts );

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.