Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created April 29, 2020 15:12
Show Gist options
  • Save ideadude/5d94276e180f1949a2c734f14865f4c6 to your computer and use it in GitHub Desktop.
Save ideadude/5d94276e180f1949a2c734f14865f4c6 to your computer and use it in GitHub Desktop.
Add a filter to the PMPro orders table to show the 30 days of orders.
<?php
/**
* Add a filter to the PMPro orders table
* in the WordPress dashboard
* to show the past 30 days of orders.
* Requires PMPro 2.3 or higher.
* Add this code through a Code Snippet or Custom Plugin.
*/
// Add the filter.
function my_pmpro_admin_orders_filters_past30( $filters ) {
$filters['past30'] = 'Past 30 Days';
return $filters;
}
add_filter( 'pmpro_admin_orders_filters', 'my_pmpro_admin_orders_filters_past30' );
// Adjust SQL based on filter.
function my_pmpro_admin_orders_query_condition_past30( $condition, $filter ) {
if ( $filter == 'past30' ) {
$now = current_time( 'timestamp' );
$start_date = date( 'Y-m-d', strtotime( '-30 days', $now ) );
$end_date = date( 'Y-m-d', $now );
$condition = "o.timestamp BETWEEN '" . esc_sql( $start_date ) . "' AND '" . esc_sql( $end_date ) . "'";
}
return $condition;
}
add_filter( 'pmpro_admin_orders_query_condition', 'my_pmpro_admin_orders_query_condition_past30', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment