按字母顺序显示产品

按字母顺序显示产品

本文介绍了Woocommerce:按字母顺序显示产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道这可能是一个愚蠢的问题,或者您可能认为它被问了几十次.但要么我绝望并错过了一些东西,要么这是一些独特的问题.不管怎样,我需要你的帮助.

Ok I know it's might be a silly question or you may think it was asked dozen times. but either I am desperate and missed something or this is some unique problem. Anyway, I need your help.

我的客户想要按字母顺序展示她的产品.当我选择默认产品排序自定义排序+名称"时,一切都很好但是后来有些事情搞砸了......排序产品"屏幕中的所有字母顺序都消失了.现在他们都按照他们的订单"号显示.

My client wanted to show her products in an alphabetic way. All was good when I select Default Product Sorting "Custom ordering + Name"But then something messed up.. and all alphabetic order in "Sort Products" Screen gone. Now they all shown according to their "Order" number.

有没有办法让产品按字母顺序返回列表?

Is there any way to make products return back to list in an alphabetic order?

我会在排序产品"中手动进行,但大约有 100 种产品,我不确定客户何时添加新产品,问题不会再出现.

I'd do it manually in "Sort Products" but there are about 100 products, and I am not sure when the client will add new products the problem won't come back.

编辑
我发现当您在开始时使用默认排序(自定义订单 + 名称)时,所有产品默认按字母顺序显示,但是一旦您将一项从字母顺序中移出(例如,将一个F"项放在在A"项目的前面)所有订单都搞砸了,只能按照产品的订单号进行订购

EDIT
I've found out that when you are using Default sorting (Custom order + Name) at the beginning all products shown by default in alphabetic order, however once you move one item out of the alphabetic order(e.g one "F" item placed in front of an "A" item) all order messed up, and follows only ordering according to product's order number

推荐答案

要扩展 @Vikas_Gautam 的答案并将其修改为按帖子标题排序,您可以执行以下操作:

To expand on @Vikas_Gautam's answer and modify it to sort by post title, you would do the following:

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );

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

    if ( 'alphabetical' == $orderby_value ) {
        $args['orderby'] = 'title';
        $args['order'] = 'DESC';
    }

    return $args;
}

add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );

function custom_woocommerce_catalog_orderby( $sortby ) {
    $sortby['alphabetical'] = __( 'Alphabetical' );
    return $sortby;
}

查看 Codex,了解 WP_Query 排序参数.

Take a look at the Codex for WP_Query sort parameters.

这篇关于Woocommerce:按字母顺序显示产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 14:53