1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Groups
  5. Reorder groups
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Product Page
  5. Reorder groups
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Advanced Topics for Add-Ons Ultimate
  5. Reorder groups
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Reorder groups

Reorder groups

By default, global groups get added after product groups. However, you might want to add your global groups first or even mix them up with the product groups.

To do this, you’ll need to use this snippet. Replace the list of group IDs in line 14 with your own list of group IDs. These will be displayed above any other groups, whether they’re global or product-level.

<?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 );

This is how to add a snippet to your site.

Was this article helpful?

Related Articles