I added a new sorting option to Woocommerce, which would sort by the lowest price. All my prices are stored in a custom attribute, along with some other serialized data. What I want is to have a callback function which would unserialize this data, check for the lowest price and sort by that price.
Every post I saw about custom ordering options, makes use of the woocommerce_get_catalog_ordering_args
filter to add orderby arguments to WP_Query, but I haven't seen any way to sort the results of the returned query via a callback function.
Is there any way to achieve this? I was looking at woocommerce_after_product_ordering
based on the name, but couldn't find much info about it. Any help would be much appreciated!
function my_woocommerce_product_sorting($orderby) {
$orderby['price_asc'] = "Sort by cheapest";
$orderby['price_desc'] = "Sort by most expensive";
return $orderby;
}
add_filter("woocommerce_catalog_orderby", "my_woocommerce_product_sorting", 20);