Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds priority to enhanced catalog attributes and display them as per their priority #2566

Merged
merged 8 commits into from
Jul 6, 2023
31 changes: 31 additions & 0 deletions includes/Admin/Enhanced_Catalog_Attribute_Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ function( $attr ) {
);
}

/**
* Attributes should be ordered by priority in this order: Length, Width, Height, Depth, Other measurement attributes, others.
*/
foreach ( $recommended_attributes as $key => $attribute ) {
if ( 'measurement' === $attribute['type'] ) {
switch ( $attribute['key'] ) {
case 'product_length':
$attr_priority = 140;
break;
case 'product_width':
$attr_priority = 130;
break;
case 'product_height':
$attr_priority = 120;
break;
case 'product_depth':
$attr_priority = 110;
break;
default:
$attr_priority = 100;
}
$recommended_attributes[ $key ]['priority'] = $attr_priority;
} else {
$recommended_attributes[ $key ]['priority'] = 5;
}

$priority[ $key ] = $recommended_attributes[ $key ]['priority'];
}

array_multisort( $priority, SORT_DESC, $recommended_attributes );

foreach ( $recommended_attributes as $attribute ) {
$this->render_attribute( $attribute );
}
Expand Down