woocommercewordpress-gutenbergwoocommerce-theming

Woocommerce filtering by attribute - how to order values by number?


There's no filter plugins in the theme. The filter is default from WooCommerce. In attributes in admin panel the sorting is correct - by name_num. But in the widget itself it's sorting alphabetically - so 8 is after 25. I tried to change the sorting in admin panel - the widget ignores it.

how it looks.

Gutenberg for widgets is not disabled.
If disable gutenberg for widgets

add_filter( 'use_widgets_block_editor', '__return_false' );

they still look like they looked before disabling, and become simply blocks in admin panel, for example

<!-- wp:woocommerce/filter-wrapper {"filterType":"attribute-filter","heading":"Filter by attribute","className":""} -->
<div class="wp-block-woocommerce-filter-wrapper"><!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">Потужність (кВт)</h3>
<!-- /wp:heading -->

<!-- wp:woocommerce/attribute-filter {"className":"inventor-filter","attributeId":13,"heading":"","lock":{"remove":true}} -->
<div class="wp-block-woocommerce-attribute-filter is-loading inventor-filter" data-attribute-id="13" data-show-counts="true" data-query-type="or" data-heading="" data-heading-level="3"><span aria-hidden="true" class="wc-block-product-attribute-filter__placeholder"></span></div>
<!-- /wp:woocommerce/attribute-filter --></div>
<!-- /wp:woocommerce/filter-wrapper -->

Maybe it's possible to add {{sortby: name_num}} or something like it?

I know that there's many plugins to make good filters, and I have not bad non-plugin snippet-filter, but it's more to do then - to change its appearance, the client already likes how it looks with gutenberg, he wants only to sort them by number value. If it's possible - how to sort attribute values in those widgets?


Solution

  • I don't know if you figured out this issue or not, but I have a solution for you. If you go to Products > Attributes, you can actually change the 'order by' of any attribute you setup. I had an attribute labeled display size and it was showing double number sizes before the single ones. I was able to change the 'default sort order' to 'custom ordering' which allowed me to go in and just drag them to the correct order to show. Time consuming that way, but at least I was able to get them to be correct. Hope that helps!