Skip to content

Instantly share code, notes, and snippets.

@marcusig
Created March 22, 2022 05:08
Show Gist options
  • Save marcusig/e8d5e52304e1b4ac0d6626ea0ed5f8da to your computer and use it in GitHub Desktop.
Save marcusig/e8d5e52304e1b4ac0d6626ea0ed5f8da to your computer and use it in GitHub Desktop.
Add a script after initialising / starting the configurator
wp.hooks.addAction( 'PC.fe.start', 'Custom_script', function( configurator ) {
// Do something here. E.g.:
// Get the viewer
var viewer = configurator.viewer.$el;
// Get the layer container
var layers_container = configurator.viewer.$( '.mkl_pc_layers' );
} );
@marcusig
Copy link
Author

This script can be added using an external file, like this:

add_action( 'mkl_pc_scripts_product_page_before', 'custom_configurator_script' ) );
function custom_configurator_script() {
	wp_enqueue_script( 'my_custom_script', MY_URL . 'add-script-after-configurator-start.js', [ 'jquery', 'wp-hooks', 'wp-util', 'backbone', 'mkl_pc/js/views/configurator' ], filemtime( MY_PATH . 'add-script-after-configurator-start.js' ), true );
}

It can also be added inline using wp_add_inline_script, as done in some of the themes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment