Guide

Multiple Choice hooks

The add-on turns a layer into one where several choices can be selected at once, and counts those selections against the layer's minimum and maximum. Its own hooks are all about that count.

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

PHP filters

HookArgumentsPurpose
mkl-multiple-choice-styles$stylesInline CSS appended to the configurator stylesheet

JavaScript filters

HookArgumentsPurpose
PC.fe.multiple_choice.item_quantityquantity, item, choiceHow much one selected item counts towards the total
PC.fe.multiple_choice.items_selected_countcount, selectedChoices, falseThe finished count for a layer

PC.fe.multiple_choice.item_quantity

Every selected item counts as 1 by default. This filter is what makes quantity-aware counting possible: return the item's quantity and a layer limited to "5 items" becomes a layer limited to five units.

javascript custom.js
wp.hooks.addFilter(	'PC.fe.multiple_choice.item_quantity',	'my-plugin/mc',	function ( quantity, item, choice ) {		return item.qty ? parseInt( item.qty, 10 ) : quantity;	});
PC.fe.multiple_choice.item_quantity.

Return a number. The result is summed across every selected item in the layer.

PC.fe.multiple_choice.items_selected_count

Filters the total once every item has been counted, immediately before it is compared against the layer's minimum and maximum. Use it to exempt certain choices from the limit:

javascript custom.js
wp.hooks.addFilter(	'PC.fe.multiple_choice.items_selected_count',	'my-plugin/mc',	function ( count, selectedChoices ) {		const free = selectedChoices.filter( ( c ) => c.is_free ).length;		return count - free;	});
PC.fe.multiple_choice.items_selected_count.

The third argument is currently always false and is reserved.

mkl-multiple-choice-styles

Inline CSS added after the configurator's own stylesheet. The add-on passes an empty string, so whatever you return is the whole of it.

php functions.php
add_filter( 'mkl-multiple-choice-styles', function ( $styles ) {	return $styles . '.mkl_pc_choice.multiple .qty { font-weight: 600; }';} );
mkl-multiple-choice-styles.

Core hooks it also fires

PC.fe.choices.add_one, PC.fe.choices.add_one.after and PC.fe.configurator.layer_data — see the Product Configurator JavaScript hooks.