Created
April 29, 2020 15:12
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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