How can I sort woocommerce grouped products by pos

2019-09-18 13:29发布

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条回答
狗以群分
2楼-- · 2019-09-18 14:04

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.

查看更多
登录 后发表回答