Skip to content

Commit

Permalink
Adds priority to enhanced catalog attributes and display them as per …
Browse files Browse the repository at this point in the history
…their priority (#2566)
  • Loading branch information
ibndawood authored Jul 6, 2023
2 parents 0bbdc81 + 9b271a3 commit 9aaf7e6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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,27 @@ function( $attr ) {
);
}

/**
* Attributes should be ordered by priority in this order: Length, Width, Height, Depth, Other measurement attributes, others.
*/
$priorities = array(
'product_length' => 140,
'product_width' => 130,
'product_height' => 120,
'product_depth' => 110,
'default' => 100,
);

foreach ( $recommended_attributes as $key => $attribute ) {
$recommended_attributes[ $key ]['priority'] = 5; // Assign 5 initially to each attribute
if ( 'measurement' === $attribute['type'] ) {
$recommended_attributes[ $key ]['priority'] = isset( $priorities[ $attribute['key'] ] ) ? $priorities[ $attribute['key'] ] : $priorities['default'];
}
$priority[ $key ] = $recommended_attributes[ $key ]['priority'];
}

array_multisort( $priority, SORT_DESC, $recommended_attributes );

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

0 comments on commit 9aaf7e6

Please sign in to comment.