php WooCommerce |按名称添加按商店归档排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WooCommerce |按名称添加按商店归档排序相关的知识,希望对你有一定的参考价值。

/*
 * Add sort by name to product archives
 */
 function ordering_args( $sort_args ) {

 $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
 switch( $orderby_value ) {

     // Name your sortby key whatever you'd like; must correspond to the $sortby in the next function
     case 'slug_asc':
       $sort_args['orderby']  = 'name';
       // Sort by ASC because we're using alphabetic sorting
       $sort_args['order']    = 'asc';
       break;
     case 'slug_desc':
       $sort_args['orderby']  = 'name';
       // Sort by DESC because we're using reverse alphabetic sorting
       $sort_args['order']    = 'desc';
       break;
 }

 return $sort_args;
 }
 add_filter( 'woocommerce_get_catalog_ordering_args', 'ordering_args' );


 // Add these new sorting arguments to the sortby options on the frontend
 function add_new_orderby( $sortby ) {

 // Adjust the text as desired
 $sortby['slug_asc'] = __( 'Sort by name: A-Z', 'woocommerce' );
 $sortby['slug_desc'] = __( 'Sort by name: Z-A', 'woocommerce' );

 return $sortby;
 }
 add_filter( 'woocommerce_default_catalog_orderby_options', 'add_new_orderby' );
 add_filter( 'woocommerce_catalog_orderby', 'add_new_orderby' );

以上是关于php WooCommerce |按名称添加按商店归档排序的主要内容,如果未能解决你的问题,请参考以下文章

php facetwp重新添加woocommerce post子句按价格排序

在 WooCommerce 商店页面上向 Ajax 添加数量字段添加到购物车按钮

WooCommerce 按用户角色删除购物车

php WooCommerce:将特色图片添加到商店页面

php 按类别筛选搜索 - woocommerce产品

php WooCommerce搜索产品按类别下拉列表