You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello.
I have recently started digging into Elasticpress code. I have faced two issues related to WooCommerce that made me edit WooCommerce.php feature.
First of all, WooCommerce allows users to create their own ordering rules with any custom field. With woocommerce_default_catalog_orderby_options and woocommerce_get_catalog_ordering_args, you can define your own ordering. For instance, let's say I want to make a sorting by discount percentage, which is saved at _discount_label field.
I had to modify the array on whitelist_meta_keys() in order to add my field.
Possible and easy solution: Adding an filter (apply_filters) so a user can add/remove fields on that array.
Second, I had to modify the translate_args at the orderby section ($_GET['orderby']) in order to add my custom ordering.
@seldimi as a workaround, you can always whitelist fields via the same filter that the WooCommerce Feature uses: ep_prepare_meta_allowed_protected_keys. That way you won't need to edit plugin code. That said, I like the idea of making the WooCommerce meta keys themselves filterable, as that makes a lot more sense from a code organization/logic standpoint. We'll discuss at our next meeting and get this slotted for development.
Great. Another feedback I could give is the double or tripe order by.
If you check $query->set('orderby') can take an array for both ASC or DESC parameters. Eg order by date DESC, discount ASC.
ElasticPress already supports multiple orderby parameters out-of-the-box. I left in this comment an example on how to do it but the gist of it is to call something like:
Hello.
I have recently started digging into Elasticpress code. I have faced two issues related to WooCommerce that made me edit WooCommerce.php feature.
First of all, WooCommerce allows users to create their own ordering rules with any custom field. With woocommerce_default_catalog_orderby_options and woocommerce_get_catalog_ordering_args, you can define your own ordering. For instance, let's say I want to make a sorting by discount percentage, which is saved at _discount_label field.
I had to modify the array on whitelist_meta_keys() in order to add my field.
Possible and easy solution: Adding an filter (apply_filters) so a user can add/remove fields on that array.
Second, I had to modify the translate_args at the orderby section ($_GET['orderby']) in order to add my custom ordering.
Then I've used the orderby_meta_mapping filter that you have, in order to set my _discount_label mapping into args.
Solution: Allow the editing of the switch of( $_GET['orderby'] )
The text was updated successfully, but these errors were encountered: