I have a specific WooCommerce category, which has an custom date field which is created by Advanced Custom Field.
I have an shortcode which outputs the products and i have found some code which is getting me a long way, but it does not register my field as an date, and does not order by that date.
The code I am using is:
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
function woocommerce_shortcode_products_orderby( $args ) {
$standard_array = array('menu_order','title','date','id', 'dato_for_anvendelse');
if($args['tax_query'][1]['terms'][0] == 'sotilbud') {
$args['meta_key'] = 'dato_for_anvendelse';
$args['orderby'] = 'meta_value_num';
}
return $args;
}
How do I make the custom field "dato_for_anvendelse" into a date that is actually sortable?
I need to order by the custom field value which is an date and find the products closest to the current date.