Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
Last active October 1, 2023 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/bc268202ed483137c795cd9b0aace2cc to your computer and use it in GitHub Desktop.
Save helgatheviking/bc268202ed483137c795cd9b0aace2cc to your computer and use it in GitHub Desktop.
Sort Mix and Match children alphabetically
<?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' ) );
}
@gurjit-git
Copy link

gurjit-git commented Oct 1, 2023

If the code does not work try to replace the filter with wc_mnm_child_items
Thanks

@helgatheviking
Copy link
Author

woocommerce_mnm_get_children is definitely deprecated. So wc_mnm_child_items is the right path. But the array of items is not the same as the array of products used to be so not entirely sure if the rest works.

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