Variations Not Using menu_order
-
For some reason custom sorting of the product variations is not working. It seems that its just looking at the terms for the order and never looks back to the variations in posts.
Here is a messy fix that seems to work for my instance.
In wc-template-functions.php in the wc_dropdown_variation_attribute_options function at line 2069 add:
// Make sure that we have visible children. if(isset($product->children['visible']) && is_array($product->children['visible']) && isset($attribute)){ $options_by_menu_order = array(); foreach($product->children['visible'] as $temp_option){ $temp_meta = get_post_meta($temp_option, "attribute_" . $attribute, true); if(!in_array($temp_meta,$options_by_menu_order)){ $options_by_menu_order[] = $temp_meta; } } }Then at line 2083 add:
if(isset($options_by_menu_order) && is_array($options_by_menu_order) && $product && taxonomy_exists( $attribute )){ // Get terms if this is a taxonomy - ordered. We need the names too. $terms = wc_get_product_terms( $product->id, $attribute, array( 'fields' => 'all' ) ); for($i = 0; $i < count($options_by_menu_order); $i++){ foreach ( $terms as $term ) { if ( in_array( $term->slug, $options ) && $term->slug == $options_by_menu_order[$i]) { $html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>'; } } } }and then make sure the next if is turned to an else if.
I’m going on the assumption that the post_meta for the variation will match the stub for the term…..but I don’t know if that is true in all instances.
Please consider adding a slightly cleaner version of this to your next version.
Let me know if you have any questions.
The topic ‘Variations Not Using menu_order’ is closed to new replies.