• Resolved timmer81

    (@timmer81)


    Hi there,

    I want to display the products I have in Date order rather than the default alphabetical order.

    I added this hook to the themes functions but did not do the trick

    add_filter(‘woocommerce_get_catalog_ordering_args’, ‘custom_woocommerce_get_catalog_ordering_args’);

    function custom_woocommerce_get_catalog_ordering_args( $args ) {
    if (isset($_SESSION[‘orderby’])) {
    switch ($_SESSION[‘orderby’]) :
    case ‘date_asc’ :
    $args[‘orderby’] = ‘date’;
    $args[‘order’] = ‘asc’;
    $args[‘meta_key’] = ”;
    break;
    case ‘price_desc’ :
    $args[‘orderby’] = ‘meta_value_num’;
    $args[‘order’] = ‘desc’;
    $args[‘meta_key’] = ‘_price’;
    break;
    case ‘title_desc’ :
    $args[‘orderby’] = ‘title’;
    $args[‘order’] = ‘desc’;
    $args[‘meta_key’] = ”;
    break;
    endswitch;
    }
    return $args;
    }

    add_filter(‘woocommerce_catalog_orderby’, ‘custom_woocommerce_catalog_orderby’);

    function custom_woocommerce_catalog_orderby( $sortby ) {
    $sortby[‘title_desc’] = ‘Reverse-Alphabetically’;
    $sortby[‘price_desc’] = ‘Price (highest to lowest)’;
    $sortby[‘date_asc’] = ‘Oldest to newest’;
    return $sortby;
    }

    I would be grateful if someone could point me in the right direction as what did seems to have not worked. Thanks in advance.

    Tim

  • The topic ‘Change Product Order in Woocommerce’ is closed to new replies.