我正在尝试在woocommerce中对价格进行分类,没有价格的产品将在分类末尾添加。
我的功能如下:
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
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 ( 'sort-price' == $orderby_value ) {
$args['orderby'] = 'CASE WHEN meta_value_num<1 THEN meta_value_num=99999 END ASC,meta_value_num';
$args['order'] = 'ASC';
$args['meta_key'] = '_price';
}
重新生成具有此功能的产品查找表后,排序如下:
1Category[1€] 1Category[2€] 1Category[No price] 2Category[1€]
为什么第二类产品不能正确分类?