简体   繁体   English

更改多个特定woocommerce产品类别的默认排序顺序

[英]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.

相关问题 更改特定 Woocommerce 产品类别存档页面的默认排序 - Change default sorting for specific Woocommerce product category archive pages 更改特定 woocommerce 类别存档的默认排序顺序 - Change default sorting order for specific woocommerce category archive 更改 Woocommerce 订单列表中的默认排序 - Change default sorting in Woocommerce order list 如果订单商品属于特定产品类别,则结帐重定向后的 Woocommerce - Woocommerce after checkout redirection if order items belongs to specific product categories 从 Woocommerce 3 中的特定产品类别中获取订单项目 - Get order items from a specific product categories in Woocommerce 3 在 WooCommerce 结账时为特定产品类别制作订单备注 - Make order notes required for specific product categories in WooCommerce checkout WooCommerce:仅针对特定产品类别设置最低订购量 - WooCommerce: Set minimum order amount for just specific product categories Woocommerce更改$ product-> get_categories的顺序 - Woocommerce change order of $product->get_categories 更改Woocommerce中特定产品类别的购物车项目价格 - Change cart item prices for specific product categories in Woocommerce 在 WooCommerce 3+ 中通过特定类别的挂钩更改产品价格 - Change product prices via a hook for specific categories in WooCommerce 3+
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM