Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abdulawal39/3e7aa796fb81df87dffb7bab182506e0 to your computer and use it in GitHub Desktop.
Save abdulawal39/3e7aa796fb81df87dffb7bab182506e0 to your computer and use it in GitHub Desktop.
Sort WooCommerce Product Attribute Values on single product page only for specific attributes. Details on: https://abdulawal.com/?p=1463
/**
* Sort Attribute values in ascending order for specific attributes
* @param array $args
* @return array return sorted $args array
*/
function abd_sort_wc_attribute_values( $args ){
if( $args['attribute'] == "Attribute Name" ){ // replace Attribute Name with your attribute's name
$get_options = $args['options'];
asort( $get_options );
$args['options'] = $get_options;
return $args;
}
}
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'abd_sort_wc_attribute_values', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment