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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change number of columns in grid layout | |
* @param int $columns | |
* @param obj $product | |
* @return int | |
*/ | |
function kia_change_mnm_columns( $columns, $product ) { | |
return 4; | |
} | |
add_filter( 'woocommerce_mnm_grid_layout_columns', 'kia_change_mnm_columns', 10, 2 ); |