Reorder the visible attributes on the frontend.
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
<?php | |
/** | |
* Reorder the visible attributes on the frontend. | |
*/ | |
add_filter( 'woocommerce_product_get_attributes', function( $old_attributes, $obj ) { | |
$order = [ 'pa_colour', 'pa_size' ]; | |
$new_attributes = []; | |
// Loop through our order items. | |
foreach ( $order as $key ) { | |
if ( isset( $old_attributes[ $key ] ) ) { | |
// Add the attribute to our new attribute array. | |
$new_attributes[ $key ] = $old_attributes[ $key ]; | |
// Remove the item from the old attribute array. | |
unset( $old_attributes[ $key ] ); | |
} | |
} | |
// Merge any possible leftover attributes into the new attribute array. | |
$new_attributes = array_merge( $new_attributes, $old_attributes ); | |
return $new_attributes; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment