woaf_saving_default_filters_settings(); $output = '
'; $output .= '

'.get_admin_page_title().'

'; $output .= '

'.__( 'Active filters:', 'woaf-plugin' ).'

'; $output .= '
'; if ( function_exists('wp_nonce_field') ) { $output .= wp_nonce_field('ant_waof_save_settings'); } $filters = $this->woaf_get_defaul_filters(); $enabled_filters = $this->woaf_enabled_additional_filters(); $per_column = ( get_option( 'woaf_per_column' ) ) ? get_option( 'woaf_per_column' ) : '4' ; if ( !empty($filters) ) { $output .= ""; } $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; $output .= '
'; if ( $save_settings ) { $output .= '

Settings saved

'; } $output .= ''; $output .= '
'; $output .= '
'; // .wrap echo $output; } function woaf_show_custom_filters_settings() { $save_settings = $this->woaf_saving_custom_filters_settings(); $filters = $this->woaf_get_custom_filters(); $output = '
'; $output .= '

'.get_admin_page_title().'

'; $output .= '
'; if ( function_exists('wp_nonce_field') ) { $output .= wp_nonce_field('waof_save_custom_filters_settings'); } $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; if ( !empty($filters) && is_array($filters) ) { $statements = $this->get_custom_field_statements(); $i = 0; foreach ($filters as $count => $filter) { $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $i++; } } else { $output .= ''; } $output .= ''; $output .= '
'.__('Name of filter', 'woaf-plugin').''.__('Statement', 'woaf-plugin').''.__('Name of field', 'woaf-plugin').''.__('Remove', 'woaf-plugin').'

'.__('No custom filters have been added.', 'woaf-plugin').'

'.__('Add custom filter', 'woaf-plugin').'
'; $output .= '
'; $output .= '
'; // .wrap $order_keys_json = $this->get_existing_order_keys_json(); if ( $order_keys_json ) { $output .= ''; } echo $output; } function woaf_get_defaul_filters() { $filters = array(); $filters[0]['name'] = __( 'Order Statuses', 'woaf-plugin' ); $filters[0]['id'] = 'order_statuses'; $filters[1]['name'] = __( 'Payment Method', 'woaf-plugin' ); $filters[1]['id'] = 'payment_method'; $filters[2]['name'] = __( 'Customer Group', 'woaf-plugin' ); $filters[2]['id'] = 'customer_group'; $filters[3]['name'] = __( 'Shipping Method', 'woaf-plugin' ); $filters[3]['id'] = 'shipping_method'; $filters[4]['name'] = __( 'Customer Email', 'woaf-plugin' ); $filters[4]['id'] = 'customer_email'; $filters[5]['name'] = __( 'Customer First Name', 'woaf-plugin' ); $filters[5]['id'] = 'customer_first_name'; $filters[6]['name'] = __( 'Customer Last Name', 'woaf-plugin' ); $filters[6]['id'] = 'customer_last_name'; $filters[7]['name'] = __( 'Customer Billing Address', 'woaf-plugin' ); $filters[7]['id'] = 'customer_billing_address'; $filters[8]['name'] = __( 'Customer Billing Country', 'woaf-plugin' ); $filters[8]['id'] = 'billing_country'; $filters[9]['name'] = __( 'Customer Phone', 'woaf-plugin' ); $filters[9]['id'] = 'customer_phone'; $filters[10]['name'] = __( 'Track Number', 'woaf-plugin' ); $filters[10]['desc'] = __( 'This filter requires Shipment Tracking plugin.', 'woaf-plugin' ); $filters[10]['id'] = 'track_number'; $filters[11]['name'] = __( 'Search by SKU Number', 'woaf-plugin' ); $filters[11]['id'] = 'search_by_sku'; $filters[12]['name'] = __( 'Orders by Date Range', 'woaf-plugin' ); $filters[12]['id'] = 'orders_by_date_range'; $filters[13]['name'] = __( 'Order Total', 'woaf-plugin' ); $filters[13]['id'] = 'filter_order_total'; return $filters; } public static function woaf_get_custom_filters() { $custom_filters = get_option('woaf_custom_filters'); if ( empty($custom_filters) ) return; //remove extra data unset($custom_filters['ID']); unset($custom_filters['filter']); return $custom_filters; } function woaf_saving_custom_filters_settings() { if ( isset($_POST['save']) && $_POST['save'] == 'woaf-save-custom-filters' ) { if ( function_exists('waof_save_custom_filters_settings') ) { check_admin_referer('waof_save_custom_filters_settings'); } if ( !empty($_POST['filter_rows']) ) { $filter_rows = sanitize_post( $_POST['filter_rows'], 'db' ); update_option( 'woaf_custom_filters', $filter_rows ); } else { update_option( 'woaf_custom_filters', '' ); } } } public static function woaf_get_filters() { $filters = []; $filters[0]['name'] = __( 'Order Statuses', 'woaf-plugin' ); $filters[0]['id'] = 'order_statuses'; $filters[1]['name'] = __( 'Payment Method', 'woaf-plugin' ); $filters[1]['id'] = 'payment_method'; $filters[2]['name'] = __( 'Customer Group', 'woaf-plugin' ); $filters[2]['id'] = 'customer_group'; $filters[3]['name'] = __( 'Shipping Method', 'woaf-plugin' ); $filters[3]['id'] = 'shipping_method'; $filters[4]['name'] = __( 'Customer Email', 'woaf-plugin' ); $filters[4]['id'] = 'customer_email'; $filters[5]['name'] = __( 'Customer First Name', 'woaf-plugin' ); $filters[5]['id'] = 'customer_first_name'; $filters[6]['name'] = __( 'Customer Last Name', 'woaf-plugin' ); $filters[6]['id'] = 'customer_last_name'; $filters[7]['name'] = __( 'Customer Billing Address', 'woaf-plugin' ); $filters[7]['id'] = 'customer_billing_address'; $filters[8]['name'] = __( 'Customer Billing Country', 'woaf-plugin' ); $filters[8]['id'] = 'billing_country'; $filters[9]['name'] = __( 'Customer Phone', 'woaf-plugin' ); $filters[9]['id'] = 'customer_phone'; $filters[10]['name'] = __( 'Track Number', 'woaf-plugin' ); $filters[10]['desc'] = __( 'This filter requires Shipment Tracking plugin.', 'woaf-plugin' ); $filters[10]['id'] = 'track_number'; $filters[11]['name'] = __( 'Search by SKU Number', 'woaf-plugin' ); $filters[11]['id'] = 'search_by_sku'; $filters[12]['name'] = __( 'Orders by Date Range', 'woaf-plugin' ); $filters[12]['id'] = 'orders_by_date_range'; $filters[13]['name'] = __( 'Order Total', 'woaf-plugin' ); $filters[13]['id'] = 'filter_order_total'; return $filters; } public static function woaf_enabled_additional_filters() { $enabled_filters = get_option( 'ant_additional_order_enabled_filters' ); if ( !empty( $enabled_filters ) ) { $enabled_filters = unserialize( $enabled_filters ); } return $enabled_filters; } function get_custom_field_statements() { $statements= array( 'equal' => '=', 'like' => 'like' ); return $statements; } function get_existing_order_keys_json() { $last_order = $this->get_last_order_id(); $fields_of_order = get_post_custom($last_order); $json = []; if ( is_array($fields_of_order) ) { foreach ($fields_of_order as $key => $field) { $json[] = $key; } } return $json; } function get_last_order_id(){ global $wpdb; $statuses = array_keys(wc_get_order_statuses()); $statuses = implode( "','", $statuses ); // Getting last Order ID (max value) $results = $wpdb->get_col( " SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type LIKE 'shop_order' AND post_status IN ('$statuses') " ); return reset($results); } } new AOF_Woo_Additional_Order_Filters_Admin_Options();