在主题的functions.php文件中加入如下代码即可:
add_filter( ‘woocommerce_get_catalog_ordering_args’, ‘custom_woocommerce_get_catalog_ordering_args’ );
add_filter( ‘woocommerce_default_catalog_orderby_options’, ‘custom_woocommerce_catalog_orderby’ );
add_filter( ‘woocommerce_catalog_orderby’, ‘custom_woocommerce_catalog_orderby’ );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET[‘orderby’] ) ? woocommerce_clean( $_GET[‘orderby’] ) : apply_filters( ‘woocommerce_default_catalog_orderby’, get_option( ‘woocommerce_default_catalog_orderby’ ) );
if ( ‘oldest_to_recent’ == $orderby_value ) {
$args[‘orderby’] = ‘date’;
$args[‘order’] = ‘ASC’;
}
return $args;
}
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby[‘oldest_to_recent’] = __( ‘产品从旧到新排序’, ‘woocommerce’ );
return $sortby;
}
添加之后,后台在外观》自定义里,WOO选项里,就会多出一个“产品从旧到新排序”的选项,,选择这个即可,如下图: