-1

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';
            break;
        case 'rand' :
            $query_args['orderby']  = 'rand';
            break;
        case 'sales' :
            $query_args['meta_key'] = 'total_sales';
            $query_args['orderby']  = 'meta_value_num';
            break;
        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';
            break;

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

0

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';
        break;

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