You should try this for Sort by last modified date order by DESC.
// Apply Sort By Last Modified
add_filter( 'woocommerce_get_catalog_ordering_args', 'woo_add_postmeta_ordering_args' );
function woo_add_postmeta_ordering_args( $args_sort ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : '';
switch( $orderby_value ) {
case 'last_modified':
$args_sort['orderby'] = 'modified';
$args_sort['order'] = 'DESC';
break;
}
return $args_sort;
}
// Add "Sort By Last Modified" option in dropdown
add_filter( 'woocommerce_default_catalog_orderby_options', 'woo_add_new_postmeta_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'woo_add_new_postmeta_orderby' );
function woo_add_new_postmeta_orderby( $sortby ) {
$sortby['last_modified'] = __( 'Sort By Last Modified', 'woocommerce' );
return $sortby;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…