Advertisement
michaellevelup

Sort products by date asc

Aug 4th, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. function enable_catalog_ordering_by_modified_date( $args ) {
  2.     if ( isset( $_GET['orderby'] ) ) {
  3.         if ( 'modified_date' == $_GET['orderby'] ) {
  4.             return array(
  5.                 'orderby'  => 'modified',
  6.                 'order'    => 'ASC',
  7.             );
  8.         }
  9.     }
  10.     return $args;
  11. }
  12.  
  13. add_filter( 'woocommerce_get_catalog_ordering_args', 'enable_catalog_ordering_by_modified_date' );
  14.  
  15. function add_catalog_orderby_by_modified_date( $orderby_options ) {
  16.     // Rename 'menu_order' label
  17.     $orderby_options['modified_date'] = __("Sort by oldest", "woocommerce");
  18.  
  19.     return $orderby_options ;
  20. }
  21.  
  22. add_filter( 'woocommerce_catalog_orderby', 'add_catalog_orderby_by_modified_date' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement