Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

wordpress - Custom sorting woocommerce products

"meta_key": "delivery_dates"
"meta_value": "a:10:{i:0;s:10:"15.01.2021";i:1;s:10:"16.01.2021";i:2;s:10:"17.01.2021";i:3;s:10:"18.01.2021";i:4;s:10:"19.01.2021";i:5;s:10:"20.01.2021";i:6;s:10:"21.01.2021";i:7;s:10:"22.01.2021";i:8;s:10:"23.01.2021";i:9;s:10:"24.01.2021";}"

I want to list my products according to the above values. There are dates in the special field I have added. For example, I want to list the products with weekend dates as in the codes below, but my codes do not work. Thank you in advance for your help.

function my_custom_ordering_options($args) {
    global $wp_query;
    if (isset($_GET['orderby'])) {
        switch ($_GET['orderby']) {

            case 'delivery_date_weekend' :
                $args = array(
                    'post_type' => 'product',
                    'meta_query' => array(
                            array(
                                'key'     => 'delivery_dates',
                                'value'   =>  array('23.01.2021', '24.01.2021'),
                                'compare' => 'IN',
                            )
                    ),
                );
                break;
        }
    }
    return $args;
}
add_filter('woocommerce_get_catalog_ordering_args', 'my_custom_ordering_options');
add_action( 'woocommerce_after_shop_loop_item', 'woo_show_product_id', 20 );

function my_custom_orderby($sortby) {
    $sortby['delivery_date_weekend'] = 'Weekend';
    return $sortby;
}
add_filter('woocommerce_catalog_orderby', 'my_custom_orderby');
question from:https://stackoverflow.com/questions/65841954/custom-sorting-woocommerce-products

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...