I am using Wordpress with Woocommerce and want to order the "Woocommerce Product Widget" by the "sales date". The default order options are "date, price, random, sales".

Within "class-wc-widget-products.php" line 50 I found

        'orderby' => array(
            'type'  => 'select',
            'std'   => 'date',
            'label' => __( 'Order by', 'woocommerce' ),
            'options' => array(
                'date'   => __( 'Date', 'woocommerce' ),
                'price'  => __( 'Price', 'woocommerce' ),
                'rand'   => __( 'Random', 'woocommerce' ),
                'sales'  => __( 'Sales', 'woocommerce' ),

Here I could add

                'sales_date'  => __( 'Sales_Date', 'woocommerce' ),

which adds the option in the drow-down menu, but how do I connect it with the actual data of the sales dates? After these drop-down entries comes the function "get_product", part of this function is this:

    switch ( $orderby ) {
        case 'price' :
            $query_args['meta_key'] = '_price';
            $query_args['orderby']  = 'meta_value_num';
        case 'rand' :
            $query_args['orderby']  = 'rand';
        case 'sales' :
            $query_args['meta_key'] = 'total_sales';
            $query_args['orderby']  = 'meta_value_num';
        default :
            $query_args['orderby']  = 'date';

So I think I have to add another case like:

        case 'sales_date_case' :
            $query_args['meta_key'] = 'sales_date';
            $query_args['orderby']  = 'meta_value_num';

But I don't know where "sales_date" comes from!

closed as off-topic by Michael, Mark Kaplun, cjbj, Dave Romsey, Howdy_McGee Apr 18 '17 at 16:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


And here is the solution! After some search I found the meta-key

 case 'sales_date' :
        $query_args['meta_key'] = '_sale_price_dates_from';
        $query_args['orderby']  = 'meta_value_num';

Not the answer you're looking for? Browse other questions tagged or ask your own question.