在Woocommerce产品中按修改日期添加排序 [英] Add sorting by modified date in Woocommerce products sort by
本文介绍了在Woocommerce产品中按修改日期添加排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在woocommerce中,我想增加在商店和档案页面中按修改日期"对产品进行排序的可能性.
In woocommerce, I would like to add the possibility to sort the products by "Modified date" in shop and archives pages.
如何在woocommerce产品分类下拉列表中添加按日期排序的日期"?
How can I add "Sort By date modified " in woocommerce product sorting dropdown?
感谢您的帮助.
推荐答案
使用以下代码可以轻松完成此操作,该代码将按修改后的日期添加排序:
This can be done very easily with the following code, which will add a sorting by modified date:
add_filter( 'woocommerce_get_catalog_ordering_args', 'enable_catalog_ordering_by_modified_date' );
function enable_catalog_ordering_by_modified_date( $args ) {
if ( isset( $_GET['orderby'] ) ) {
if ( 'modified_date' == $_GET['orderby'] ) {
return array(
'orderby' => 'modified',
'order' => 'DESC',
);
}
}
return $args;
}
add_filter( 'woocommerce_catalog_orderby', 'add_catalog_orderby_by_modified_date' );
function add_catalog_orderby_by_modified_date( $orderby_options ) {
// Rename 'menu_order' label
$orderby_options['modified_date'] = __("Sort by modified date", "woocommerce");
return $orderby_options ;
}
代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试和工作.
Code goes in function.php file of your active child theme (or active theme). Tested and work.
这篇关于在Woocommerce产品中按修改日期添加排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文