wordpress - 更改特定 Woocommerce 产品类别存档页面的默认排序
问题描述
我找到了这段代码,但它只适用于我想添加三个或四个类别的一个类别
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_catalog_ordering_args', 20, 1 );
function custom_catalog_ordering_args( $args ) {
$product_category = 't-shirts'; // <== HERE define your product category
// Only for defined product category archive page
if( ! is_product_category($product_category) ) return $args;
// Set default ordering to 'date ID', so "Newness"
$args['orderby'] = 'date ID';
if( $args['orderby'] == 'date ID' )
$args['order'] = 'DESC'; // Set order by DESC
return $args;
}
解决方案
推荐阅读
- jquery - 试图找到包含然后匹配数字的属性
- progressive-web-apps - iOS 上 PWA 中的后退按钮
- pandas - 如何对一个值进行分组,对一列求和并在另一列中保持相等的值?
- javascript - 我在尝试为脚本机器人运行 .exe 时收到 {"error":"Invalid request"}
- crystal-lang - 如何从字符串调用实例方法?
- arrays - 遍历数组并根据一个或多个搜索条件返回多行
- swift - macOS 上的 SwiftUI - 同时处理单击和双击
- sql - “*”是否确保特定的列排序?
- html - 不需要的中心对齐
- go - 带有授权标头的 307 重定向