Home:ALL Converter>Set custom product sorting as default Woocommerce sorting option

Set custom product sorting as default Woocommerce sorting option

Ask Time:2018-12-03T16:05:17         Author:Mani

Json Formatter

In Woocommerce, I ma using the following code that adds a custom sorting option to shop catalog by modified date.

add_filter( 'woocommerce_get_catalog_ordering_args', 'enable_catalog_ordering_by_modified_date' );
function enable_catalog_ordering_by_modified_date( $args ) {
    if ( isset( $_GET['orderby'] ) ) {
        if ( 'modified_date' == $_GET['orderby'] ) {
            return array(
                'orderby'  => 'modified',
                'order'    => 'DESC',
            );
        }
    }
    return $args;
}

add_filter( 'woocommerce_catalog_orderby', 'add_catalog_orderby_by_modified_date' );
function add_catalog_orderby_by_modified_date( $orderby_options ) {
    // Rename 'menu_order' label
    $orderby_options['modified_date'] = __("Sort by modified date", "woocommerce");

    return $orderby_options ;
}

From this answer: Add sorting by modified date in Woocommerce products sort by

I would like to make that custom sorting option as the default sorting option keeping the default woocommerce option (by menu order) as a secondary option.

How can I set this sorting as woocommerce default?

Author:Mani,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53589711/set-custom-product-sorting-as-default-woocommerce-sorting-option
yy