Last active
October 1, 2023 20:29
-
-
Save helgatheviking/bc268202ed483137c795cd9b0aace2cc to your computer and use it in GitHub Desktop.
Sort Mix and Match children alphabetically
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' ) ); | |
} | |
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
If the code does not work try to replace the filter with
wc_mnm_child_items
Thanks