How is it possible to sort WooCommerce products by Advanced Custom Field values?
I've added some custom fields to the back-end and front-end of the website. The front-end implementation in my functions.php looks like so:
add_action( 'woocommerce_before_add_to_cart_form', 'tmy_eventbooking', 20 );
function tmy_eventbooking() {
if( !empty( get_field('datum') ) ) { // if your custom field is not empty…
echo '<p class="acf-info">Findet statt am: <span>' . get_field('datum') . '</span></p>';
}
if( !empty( get_field('datum_ende') ) ) { // if your custom field is not empty…
echo '<p class="acf-info">Bis: <span>' . get_field('datum_ende') . '</span></p>';
}
if( !empty( get_field('veranstaltungsort') ) ) { // if your custom field is not empty…
echo '<p class="acf-info">Ort: <span>' . get_field('veranstaltungsort') . '</span></p>';
}
return;
}
This works fine.
Now I would like to be able to sort products by these ACF fields (type date and text).
If a user clicks for example on a 'date' button or selects a location from a dropdown menu, all events get sorted accordingly. Events are regular WooCommerce service products.
What is a good way to approach this?