
Hey there,
I created a date field for my products on woocommerce. Then Sorted my products based on that date. How can I get a dynamic number for my products based on that date.
1st product date is 10/05/2019
2nd product date is 15/05/2019
3rd product date is 12/05/2019
Give products numbers like this:
1st product date is 10/05/2019 Product number 1
3rd product date is 12/05/2019 Product number 2
2nd product date is 15/05/2019 Product number 3
function hh_execution_date_ordering( $sort_args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'execution_date' == $orderby_value ) {
$sort_args['orderby'] = 'meta_value';
$sort_args['order'] = 'DESC';
$sort_args['meta_key'] = 'exe_date';
}
return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'hh_execution_date_ordering' );
function hh_custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['execution_date'] = 'Sort by execution date';
return $sortby;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'hh_custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'hh_custom_woocommerce_catalog_orderby' );