PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Sort products by Date property

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

The filter seems to sort by date but as I am using the European Date format it starts with 02.10.2025 and for example 22.09.205 comes afterwards. How can I solve this?

https://tischreservierung-oktoberfest.de/shop/?swoof=1&pa_festzelt=kaefers-wiesn-schaenke

Edit: I just realized the filter must be sorting by title, as the date is in the title. I set the dates fo the products as properties, how can I sort by property date ascending by default?

Hello,

In your case, the"date" is just a string inside the product title, so it cannot be used for proper sorting in its current form.
To implement the sorting logic you need, it is necessary to store the date in a dedicated custom meta field (for example, _event_date_ts) in a sortable format — preferably as a UNIX timestamp or as YYYY-MM-DD. This will ensure correct ordering.

Once you have such a meta field, you can add the following snippet to your theme’s functions.php file. It will create a new “Date (custom, oldest first)” sorting option in the shop and make it work both in WooCommerce default loops and in HUSKY:

add_filter('woocommerce_catalog_orderby', function ($options) {
$options['eventdate-asc'] = __('Date (custom, oldest first)', 'your-textdomain');
return $options;
});

add_filter('woocommerce_default_catalog_orderby', function () {
return 'eventdate-asc';
});

add_filter('woocommerce_get_catalog_ordering_args', function ($args, $orderby, $order) {
$orderby_req = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : $orderby;
if ($orderby_req === 'eventdate-asc') {
$args['meta_key'] = '_event_date_ts';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
}
return $args;
}, 10, 3);

add_filter('woof_order_catalog', function ($args) {
$orderby_req = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : '';
if ($orderby_req === 'eventdate-asc' || $orderby_req === '') {
$args['meta_key'] = '_event_date_ts';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
}
return $args;
});

After adding this code:

  • Create or update the _event_date_ts meta field for each product.
  • Store the date as a UNIX timestamp (or YYYY-MM-DD) so sorting works correctly.
  • Select “Date (custom, oldest first)” from the sorting dropdown, or let it be used by default.

Please try and do tests ...

Is there a way to use the product attribute? I have set the date as pa_datum and they are already in the correct order:

Hello

Events are something that happen at a specific point in time — they are temporary. An attribute, on the other hand, is meant to describe a permanent characteristic of a product, such as its color, size, or other fixed properties. In your case, what you actually need is a timestamp (date field) stored as product meta, not an attribute. This will allow you to sort products correctly by date and, if needed, filter them by a date range.

Since your website deals with events, imagine how many separate attributes you would need to create. More importantly, using attributes for this purpose is not the right way to store such data. For example, if you ever want to see how many events took place within a specific date range, this approach would cause unnecessary difficulties, because you would be relying on attribute names instead of proper date values. Of course, a good developer could work around this, but it’s not an efficient or scalable solution — and in this case, it’s simply not the right tool for the job.