1. Documentation /
  2. Mix and Match Products /
  3. Mix and Match: Tips, Tricks and Snippets

Mix and Match: Tips, Tricks and Snippets

In this document, you will find a growing list of useful snippets for customizing the appearance and functionality of Mix and Match. To use a snippet, you can copy the contained code into a site-specific plugin, or into your child theme’s functions.php file

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our  Support Policy.

Alphabetically order Mix and Match child products

↑ Back to top
<?php
/**
* Sort the mix and match children alphabetically
*
* @param array $children : an array of $product objects
* @param obj $product : the container product
* @return array
*/
function mnm_order_children_args( $children, $product ){
uasort( $children, 'mnm_alpha_order_children' );
return $children;
}
add_filter( 'woocommerce_mnm_get_children', 'mnm_order_children_args', 10, 2 );
/**
* Callback for uasort
* string compare the post titles
*
*/
function mnm_alpha_order_children( $a, $b ){
return strcmp( $a->get_title( 'edit' ), $b->get_title( 'edit' ) );
}

Display child product descriptions

↑ Back to top
<?php
/**
* Display individual MNM option descriptions
*
* @param obj $mnm_item WC_Product of child item
* @param obj WC_Mix_and_Match $product the parent container
*/
function kia_add_individual_info( $mnm_item, $parent_product ) {
echo '<p class="desc">' . $mnm_item->get_short_description() . '</p>';
}
add_action( 'woocommerce_mnm_child_item_details', 'kia_add_individual_info', 65, 2 );

Display child product prices

↑ Back to top
Note, the prices are automatically displayed as of Mix and Match 1.4.0 when in per-item pricing mode.
<?php
/**
* Display individual MNM option prices
*
* @param obj $mnm_item WC_Product of child item
* @param obj WC_Mix_and_Match $product the parent container
*/
function kia_add_individual_prices( $mnm_item, $parent_product ) {
if( $parent_product->is_priced_per_product() ) {
echo '<p class="price">' . $mnm_item->get_price_html() . '</p>';
}
}
add_action( 'woocommerce_mnm_child_item_details', 'kia_add_individual_prices', 65, 2 );

Remove thumbnail column

↑ Back to top
<?php
/**
* Remove thumbnail column from MNM product options
* The table column header must be removed by overriding the single-product/mnm/tablular/mnm-items-wrapper-open.php template
*/
function kia_remove_thumbnail_column() {
remove_action( 'woocommerce_mnm_child_item_details', 'wc_mnm_template_child_item_thumbnail_open', 10 );
remove_action( 'woocommerce_mnm_child_item_details', 'wc_mnm_template_child_item_thumbnail', 20 );
remove_action( 'woocommerce_mnm_child_item_details', 'wc_mnm_template_child_item_section_close', 30 );
add_filter( 'woocommerce_mnm_tabular_column_headers', 'kia_remove_thumbnail_column_header' );
}
add_action( 'woocommerce_before_mnm_items', 'kia_remove_thumbnail_column', -10 );
/**
* Remove thumbnail column from MNM table header
* @param array
* @return array
*/
function kia_remove_thumbnail_column_header( $headers ) {
if( isset( $headers['thumbnail'] ) ) {
unset( $headers['thumbnail'] );
}
return $headers;
}

Change number of columns in grid layout

↑ Back to top
https://gist.github.com/helgatheviking/85e18c1cb46b7191951de69fbe4a004b