How can I sort woocommerce grouped products by post date instead of menu order?

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:51:13

问题


What code/filter can I add to my wordpress functions.php file to modify the order of grouped products by post date instead of menu_order? class-wc-product-grouped.php

$args = apply_filters( 'woocommerce_grouped_children_args', array(
    'post_parent'   => $this->id,
    'post_type'     => 'product',
    'orderby'       => 'menu_order',
    'order'         => 'ASC',
    'fields'        => 'ids',
    'post_status'   => 'publish',
    'numberposts'   => -1,
) );

I'm pretty sure you can hook into it but just not sure how to configure the following filter/hook woocommerce_grouped_children_args


回答1:


As you have mentioned, you just need to filter the $args being passed through the woocommerce_grouped_children_args filter.

add_filter( 'woocommerce_grouped_children_args', 'so_29973708_grouped_children_args' );
function so_29973708_grouped_children_args( $args ){
    $args['orderby'] = 'date';
    $args['order'] = 'DESC';
    return $args;
}

If you need help understanding filters, I wrote what I think is a pretty good tutorial on how to use filters

Update If you aren't seeing any changes, chances are that the grouped product's children have already been stored in a transient. You will need to delete this transient to see changes right away. You can clear all WooCommerce product transients via the Admin. Navigate to WooCommerce>System Status>Tools and click on the button to clear transients.



来源:https://stackoverflow.com/questions/29973708/how-can-i-sort-woocommerce-grouped-products-by-post-date-instead-of-menu-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!