Created
March 4, 2020 09:49
-
-
Save plugin-republic/a9151a343b332401be12b9510baf89c3 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Reorder groups | |
*/ | |
function prefix_filter_product_extra_groups( $groups, $post_id ) { | |
if( empty( $groups ) ) return $groups; | |
/** | |
* Here's a list of groups that we want to appear first | |
* Enter your list of group IDs in the list below, separated by commas | |
* Any groups you don't add here will just get added after these groups | |
*/ | |
$priority_groups = array( 2803, 5138 ); | |
// This is the newly ordered list of all groups | |
$new_order = array(); | |
if( $priority_groups ) { | |
foreach( $priority_groups as $pg_id ) { | |
if( isset( $groups[$pg_id] ) ) { | |
// Add priority groups to our array | |
$new_order[$pg_id] = $groups[$pg_id]; | |
} | |
} | |
} | |
// Now add the remaining groups in the original list, excluding priority groups | |
foreach( $groups as $g_id=>$group ) { | |
if( ! in_array( $g_id, $priority_groups ) ) { | |
// If this group isn't already in our priority group, then we can add it now | |
$new_order[$g_id] = $groups[$g_id]; | |
} | |
} | |
return $new_order; | |
} | |
add_filter( 'pewc_filter_product_extra_groups', 'prefix_filter_product_extra_groups', 100, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment