Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created January 21, 2025 03:59
Show Gist options
  • Save kartikparmar/04d310fd581a00e98d63c909d6247bc0 to your computer and use it in GitHub Desktop.
Save kartikparmar/04d310fd581a00e98d63c909d6247bc0 to your computer and use it in GitHub Desktop.
Sorting attributes in custom order
<?php
/**
* Modify sorting pattern for size attribute.
*/
function swpco_weekdays() {
/* Following data is assumption that you want the size order in mentioned order. */
return array(
's' => 'aaaaaaaaa',
'm' => 'aaaaaaaab',
'l' => 'aaaaaaaac',
'xl' => 'aaaaaaaad',
'xxl' => 'aaaaaaaae',
'xxxl' => 'aaaaaaaaf',
);
}
add_filter( 'swpco_weekdays', 'swpco_weekdays', 10, 1 );
/**
* Modify sorting type for size attribute.
*/
function return_type_of_attribute( $type ) {
return 'weekday';
}
add_filter( 'swpco_attribute_type', 'return_type_of_attribute', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment