简体   繁体   English

更改 Woocommerce 类别下拉顺序

[英]Change Woocommerce category dropdown order

I am using this to display a dropdown of product categories on specific Woocommerce pages:我正在使用它在特定的 Woocommerce 页面上显示产品类别的下拉列表:

add_action( 'woocommerce_before_shop_loop', 'get_product_subcategories_list', 1 );
function get_product_subcategories_list( $category_slug ){
$cat = get_queried_object();
                    $cat_id = $cat->term_id;
                    $args = array(
                        'taxonomy' => 'product_cat',
                        'title_li' => '',
                        'child_of' => $cat_id,
                    );
   if ( is_product_category(array( 17,25 )  )  ) {     
                    ?><div class="subcategories"><?php wc_product_dropdown_categories($args);  ?></div><?php
       wc_enqueue_js( "
  $('#product_cat').change(function () {
     location.href = '/?product_cat=/'+$(this).val();
  });
  " );
}}

The dropdown is displaying the categories in alphabetical order, but I need them to be displayed in the sorting that I have set in the backend.下拉列表按字母顺序显示类别,但我需要将它们显示在我在后端设置的排序中。 How can I change this?我怎样才能改变这个?

I had a similar problem but the code I'm using is a bit different.我有一个类似的问题,但我使用的代码有点不同。 Does it work if you add如果你添加它是否有效

'orderby' => 'order'

to your args list?到你的 args 列表?

So like this所以像这样

     $args = array(
    'taxonomy' => 'product_cat',
    'title_li' => '',
    'child_of' => $cat_id,
    'orderby'  => 'order',
                );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM