Support

Account

Home Forums General Issues Get a number for product

Unread

Get a number for product

    • mv_mk

    • June 18, 2019 at 12:47 pm

    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' );
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.