Last active
May 5, 2020 00:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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