dongren4147 2015-05-26 09:33
浏览 17

按字母顺序排列WoCommerce产品ASC和DESC

I'm facing a problem with the product sorting order. I need them to be sorted alphabeticaly both ways. While I have managed to implement the order options, when I go from ASC to DESC and then back again to ASC, the ordering doesn't work.

Here's my implementation:

// 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;
}

Thanks!

  • 写回答

1条回答 默认 最新

  • dongxi5494 2015-05-26 09:50
    关注

    Follow this.. you can do as it will help you.

    https://gist.github.com/mikejolley/1622644

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题