如何按发布日期而不是菜单顺序对woocommerce分组产品进行排序? [英] How can I sort woocommerce grouped products by post date instead of menu order?

查看:563
本文介绍了如何按发布日期而不是菜单顺序对woocommerce分组产品进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在wordpress functions.php文件中添加什么代码/过滤器,以通过发布日期而不是menu_order修改分组产品的顺序? class-wc-product-grouped.php (

$ b pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' " id,
'post_type'=>'product',
'orderby'=>'menu_order',
'order'=>'ASC',
'fields'=>'id',
'post_status'=>'publish',
'numberposts'=> -1,
));

我敢肯定你可以挂钩,但不确定如何配置下面的过滤器/ hook woocommerce_grouped_children_args

解决方案正如你所提到的,你只需要过滤通过 woocommerce_grouped_children_args 过滤器传递的 $ args

  add_filter('woocommerce_grouped_children_args','so_29973708_grouped_children_args'); 
函数so_29973708_grouped_children_args($ args){
$ args ['orderby'] ='date';
$ args ['order'] ='DESC';
返回$ args;



$ b如果你需要帮助理解过滤器,我写了我认为是相当不错的如何使用过滤器



更新如果您没有看到任何更改,则分组产品的子项可能已经存储在临时文件中。您将需要删除此瞬态以便立即查看更改。您可以通过管理员清除所有WooCommerce产品瞬变。导航到 WooCommerce>系统状态>工具,然后点击按钮清除瞬变。


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

解决方案

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.

这篇关于如何按发布日期而不是菜单顺序对woocommerce分组产品进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆