[英]Change default sorting order for multiple specific woocommerce product categories
I'm trying to change the default orderby for multiple product categories, but can't work out how to adapt the code found here Cant change default sorting order of specific woocommerce category to 'popularity' to apply the change to more than one category. 我正在尝试更改多个产品类别的默认排序 ,但是无法弄清楚如何修改此处找到的代码。 无法将特定woocommerce类别的默认排序顺序更改为“受欢迎程度”,以将更改应用于多个类别。
Here's the code I currently have that is changing the default orderby for my comic book preorders category: 这是我当前拥有的代码,用于更改我的漫画书预订类别的默认orderby:
add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' );
function custom_default_catalog_orderby() {
$product_category = 'comic-book-pre-orders';
if ( is_product_category( $product_category ) ) {
return 'sku_asc';
}
else {
return 'date';
}
}
Ideally I'd be able to apply the custom orderby to my 'comic-book-subscriptions' category as well as a couple of others potentially. 理想情况下,我可以将自定义订单依据应用于我的“漫画书订阅”类别以及其他两个类别。
Any help would be very much appreciated! 任何帮助将不胜感激!
Kind regards, JP 亲切的问候,JP
Think I managed to work it out! 认为我设法解决了!
Here's the code I'm now using: 这是我现在使用的代码:
add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' );
function custom_default_catalog_orderby() {
$product_category = array( 'comic-book-pre-orders', 'comic-book-subscriptions' );
if ( is_product_category( $product_category ) ) {
return 'sku_asc';
}
else {
return 'date';
}
}
If anyone has a better approach please let me know :) 如果有人有更好的方法,请告诉我:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.