我遇到了产品分类订单的问题。我需要它们按字母顺序排序。虽然我已设法实现订单选项,但当我从ASC转到DESC然后再转回ASC时,订购无效。
这是我的实施:
// Custom sorting options (asc/desc)
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args', 10, 1 );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'asc_list' == $orderby_value ) {
$args['orderby'] = 'slug name title';
$args['order'] = 'ASC';
$args['meta_key'] = '';
}
else if ( 'desc_list' == $orderby_value ) {
$args['orderby'] = 'slug name title';
$args['order'] = 'DESC';
$args['meta_key'] = '';
}
return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['asc_list'] = 'A-Z';
$sortby['desc_list'] = 'Z-A';
return $sortby;
}
谢谢!