Guide

Conditional Logic hooks

Conditional Logic evaluates the rules configured on a product every time a choice changes, then shows, hides, disables, selects or resets layers and choices accordingly. Everything it exposes is JavaScript — there are no PHP hooks in this add-on.

The actions let you react to what the rules did; the filters let you change how the add-on applies them.

See the hook reference index for how to register JavaScript callbacks.

JavaScript actions

HookArgumentsPurpose
mkl_checked_conditions(none)A full evaluation pass has finished
conditions.set_choice.afterchoiceRules have been re-evaluated after a choice was selected
mkl_conditions_show_hide_choicechoiceView, showA choice was shown or hidden by a rule
mkl_conditions_disabled_choicechoiceView, disabledA choice was enabled or disabled by a rule
conditional.selected_layerlayerA rule opened or selected a layer
conditional/reset_layerlayerA Reset action ran on a layer
conditional/reset_choicechoice, layerA Reset action ran on a choice or group

JavaScript filters

HookArgumentsPurpose
mkl_pc_conditionals.proceedproceedWhether to apply a condition's actions
mkl_pc_conditionals.toggle_choicestoggleChoicesWhether hiding a layer also hides its choices
mkl_pc_conditionals.use_jquery_toggleuseToggleWhether layers are hidden with jQuery .toggle()
mkl_pc_conditionals.hide_triggering_layertrueWhether selecting a layer closes the one clicked

mkl_checked_conditions

Fires once at the end of every evaluation pass, after all matching rules have been applied. This is the hook to use when you need the settled state — individual show/hide actions fire while the pass is still running, and a later rule may undo what an earlier one did.

javascript custom.js
wp.hooks.addAction( 'mkl_checked_conditions', 'my-plugin/cl', function () {	const visible = PC.fe.layers.filter( ( l ) => false !== l.get( 'cshow' ) );	console.log( 'visible layers:', visible.length );} );
mkl_checked_conditions.

It takes no arguments — read the current state from PC.fe.layers and the choice collections.

mkl_conditions_show_hide_choice and mkl_conditions_disabled_choice

Fire per choice, as the pass applies each rule. Both receive the choice's Backbone view, not its model — reach the model with view.model.

javascript custom.js
wp.hooks.addAction(	'mkl_conditions_disabled_choice',	'my-plugin/cl',	function ( choiceView, disabled ) {		choiceView.$el.attr( 'title', disabled ? 'Not available with your current selection' : '' );	});
mkl_conditions_show_hide_choice and mkl_conditions_disabled_choice.

mkl_conditions_show_hide_choice is passed show (true when becoming visible); mkl_conditions_disabled_choice is passed disabled (true when becoming unavailable). Note that they are opposites of each other, which is easy to get wrong.

conditional/reset_layer and conditional/reset_choice

Fire when a rule's Reset action clears a selection — worth hooking if you keep state of your own alongside the configurator's and need to clear it too.

javascript custom.js
wp.hooks.addAction( 'conditional/reset_choice', 'my-plugin/cl', function ( choice, layer ) {	delete myState[ layer.id ];} );
conditional/reset_layer and conditional/reset_choice.

mkl_pc_conditionals.proceed

Checked for each condition just before its actions run. Return false to skip that condition entirely — the escape hatch when a rule needs to depend on something the rule builder cannot express, such as the customer's role or the contents of the cart.

javascript custom.js
wp.hooks.addFilter( 'mkl_pc_conditionals.proceed', 'my-plugin/cl', function ( proceed ) {	return myWholesaleCustomer ? false : proceed;} );
mkl_pc_conditionals.proceed.

The filter receives only the running proceed value, so it applies to every condition on the product. To target one rule, gate on state you set elsewhere.

mkl_pc_conditionals.toggle_choices and mkl_pc_conditionals.use_jquery_toggle

Both control how a hidden layer disappears, which matters if your theme animates the configurator or uses CSS rather than inline styles.

toggle_choices defaults to true for top-level layers and false for child layers — hiding a child layer leaves its choices alone. use_jquery_toggle defaults to true except for step layers; return false and the add-on only toggles the cshow-hidden class, leaving the appearance entirely to your CSS:

javascript custom.js
wp.hooks.addFilter( 'mkl_pc_conditionals.use_jquery_toggle', 'my-plugin/cl', function () {	return false; // style .cshow-hidden yourself} );
mkl_pc_conditionals.toggle_choices and mkl_pc_conditionals.use_jquery_toggle.

mkl_pc_conditionals.hide_triggering_layer

When a rule selects or opens a layer, the add-on closes the layer the customer just clicked in, so the configurator moves the customer along. Return false to leave both open.

javascript custom.js
wp.hooks.addFilter( 'mkl_pc_conditionals.hide_triggering_layer', 'my-plugin/cl', function () {	return false;} );
mkl_pc_conditionals.hide_triggering_layer.

Core hooks it also fires

PC.fe.configurator.layer_data and PC.fe.configurator.choice_data — see the Product Configurator JavaScript hooks.