Support

Account

Home Forums General Issues Sorting woocommerce products by ACF Date Picker field Reply To: Sorting woocommerce products by ACF Date Picker field

  • I can’t edit my reply so I have to write a new one. I’ve checked into database, and I saw that the custom field date_end is saved in the following format:
    02/April/2022
    So I’ve tried to manipulate and change the code:

    add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_catalog_orderby');
    function woocommerce_catalog_orderby( $args ) {
        // <- define category slug- returns true or false
            $args['order']    = 'ASC'; // <- order ASC or DESC
            $args['meta_key'] = 'date_end'; // <- _price is meta_value_num's key - required'
            $args['orderby'] = date('Ymd', strtotime(preg_replace("/\//", " ", 'meta_value')));
    
        return $args;
    }

    But again, I don’t have correct ordering.