• Resolved schmago

    (@schmago)


    Hi,

    I would like to schedule an export with last month orders, but using the completed date instead of the default one.

    I tried to use and custom your code samples :

    // replace {yesterday} and {today}  with actual values comparison operators
    // tweak formats for your needs!
    add_filter('woe_settings_validate_defaults', function ($settings) {
    	$settings = json_encode($settings); // to string
    	$yesterday = date("Y-m-d" , strtotime("-1 day",  current_time( 'timestamp' ) ));
    	$settings = str_replace( '{yesterday}', $yesterday, $settings);
    	$today = date("Y-m-d" , current_time( 'timestamp' ) );
    	$settings = str_replace( '{today}', $today, $settings);
    	$settings = json_decode($settings, true); // to array
    	return $settings;
    } );

    but in the section “filter by order” > “custom fields”,
    should I use
    _completed_date LIKE {tomorrow}
    or

    _completed_date >= {today}
    _completed_date <= {tomorrow}

    Thanks.

    • This topic was modified 2 years, 5 months ago by schmago.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    please, use

    _completed_date LIKE {tomorrow}

    Thread Starter schmago

    (@schmago)

    Thanks for quick answer.
    Unfortunately, the result is not what I was looking for.
    I want to have a date range like :
    1st day of last mont <= _completed_date <= last day of last month

    So I custom the tomorrow and today value :

    
    $tomorrow = date("Y-m-d", strtotime('last day of -1 month'));
    $today = date("Y-m-d", strtotime('first day of -1 month'));
    

    But I only get orders from the last day of last month (1 day)
    when I use
    _completed_date LIKE {tomorrow}

    and when I am on debug mode, I only see one condition link to the tomorrow date :
    (ordermeta_cf_1.meta_value LIKE '%2021-09-30%' )

    • This reply was modified 2 years, 5 months ago by schmago.
    • This reply was modified 2 years, 5 months ago by schmago.
    Plugin Author algol.plus

    (@algolplus)

    Hello

    please, use these conditions

    _completed_date >= {today} 00:00:00
    _completed_date <= {tomorrow} 00:00:00

    And you must add this code to section “Misc Settings”

    add_filter( "woe_compare_field_cast_to_type", function($type, $field, $operator, $value, $public_fieldname){
    if($public_fieldname == "_completed_date") $type = "date";
    return $type;
    },10,5); 
    Thread Starter schmago

    (@schmago)

    Works great, thank you very much!

    Plugin Author algol.plus

    (@algolplus)

    you’re very welcome

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Export date range using an other date field’ is closed to new replies.