Sales report is the most important part for marketing strategies. You should have a clear view of your customer interest about your store. Here we discuss woocommerce report by payment method. By default woocommerce has a very good reporting system like reports by order , by customer , by product stock etc but there is no option to check how many sales are made by which payment gateway. Like you have 3 active payment option Paypal , Credit/Debit card and COD now if you need to know how many sales from Paypal or how many sales from cards in last week or last month then this article will help you a lot and you are in the right place just follow all instruction discuss below.

If you need any custom woocommerce plugin development or any woocommerce customization please contact me. I’ll be happy to help you.
How woocommerce sales report by payment gateway works?
Before we discuss this lets see what’s the by default inbuild reporting system of woocommerce. Under admin left woocommerce menu there is an option for Reports from here we can see all orders by date , by products.

So here is no option to check how many orders through which payment method and the total sale amount.
For this custom option we need a panel in wordpress admin section so we are going to create a separate menu in admin left menu panel called Reports by payment method. We need a wordpress default hook and action. Here is the main hook admin_menu
and action add_menu_page
, below is the sample code how to create a custom admin menu.
add_action('admin_menu', 'a2zwp_woo_payment_gateway_report_settings_page');
function a2zwp_woo_payment_gateway_report_settings_page(){
add_menu_page(
'Reports By Payment Method',
'Reports By Payment Method',
'manage_options',
'payment-gateway-report-settings.php',
'payment_gateway_report_settings_page'
);
}
You need to put this code under theme function.php
page. It’s create the page where you can see the report.

This is the filtration process so we can here filter it by any in-between dates. There are 6 quick access button which helps you filter quickly like by today , yesterday , last 7 days, last 30 days.
To show this filtration process you need to put below code. Basically we mention the function name on the add_menu_page
action so it’s name payment_gateway_report_settings_page
now we need to put the filtration code under this function it’s looks like
function payment_gateway_report_settings_page(){
$output = '';
}
Here $output is the main return variable from this function so we need to put the HTML part within this variable.
$output .= '<h2>Filter Report By Date Range :-</h2><form action="" method="post">From Date: <input type="text" name="searchstartdate" placeholder="YYYY-MM-DD" value="'.$inputboxstartval.'"> To Date: <input type="text" name="searchenddate" placeholder="YYYY-MM-DD" value="'.$inputboxendval.'"> <input class="button button-primary" type="submit" name="submitdate" value="Check Report"></form><h2>Filter Report By Quick Access Button :-</h2><a class="button button-primary" href="admin.php?page=payment-gateway-report-settings.php×pan=5">Today Report</a> <a class="button button-primary" href="admin.php?page=payment-gateway-report-settings.php×pan=1">Yesterday Report</a> <a class="button button-primary" href="admin.php?page=payment-gateway-report-settings.php×pan=2">Last Week Report</a> <a class="button button-primary" href="admin.php?page=payment-gateway-report-settings.php×pan=4">Last 7 Days Report</a> <a class="button button-primary" href="admin.php?page=payment-gateway-report-settings.php×pan=3">Last 30 Days Report</a> <a class="button button-primary" href="admin.php?page=payment-gateway-report-settings.php×pan=6">Last Month Report</a> <a href="admin.php?page=payment-gateway-report-settings.php" class="button button-secondary">Reset</a>';
Now we need to check what are the payment gateway active for that we need to follow this below code.
$active_gateways = array();
$gateways = WC()->payment_gateways->payment_gateways();
foreach ( $gateways as $id => $gateway ) {
$active_gateways[ $id ] = array(
'title' => $gateway->title,
'supports' => $gateway->supports,
);
}
So under active_gateways
variable we store the active payment gateway list. Now we need to set the start and end date for filtration process, we can use if-else condition or switch-case condition , 1st need to check form POST data, here is the sample code you can modify it as per your needs.
global $wpdb;
$status = 0;
if($_POST['searchstartdate']!=''){
$date_from = $_POST['searchstartdate'];
$date_to = $_POST['searchenddate'];
$status = 1;
}
elseif($_GET['timespan']==1){
$yesterdayDate =date('Y-m-d',strtotime("-1 days"));
$date_from = $yesterdayDate;
$date_to = $yesterdayDate;
$status = 1;
}
elseif($_GET['timespan']==2){
$date_from = date("Y-m-d", strtotime("last week monday"));
$date_to = date("Y-m-d", strtotime("last sunday"));
$status = 1;
}
elseif($_GET['timespan']==3){
$date_from = date('Y-m-d',strtotime("-30 days"));
$date_to = date('Y-m-d',strtotime("-1 days"));
$status = 1;
}
elseif($_GET['timespan']==4){
$date_from = date('Y-m-d',strtotime("-7 days"));
$date_to = date('Y-m-d',strtotime("-1 days"));
$status = 1;
}
elseif($_GET['timespan']==5){
$date_from = date('Y-m-d',strtotime("today"));
$date_to = date('Y-m-d',strtotime("today"));
$status = 1;
}
elseif($_GET['timespan']==6){
$date_from = date('Y-m-d',strtotime("first day of previous month"));
$date_to = date('Y-m-d',strtotime("last day of previous month"));
$status = 1;
}
How to fetch the order data as per date filter
This is the most important part about this topic because by this code you can get the order data with filtration. After that you can just print it with foreach
looping concepts.
$post_status = implode("','", array('wc-processing', 'wc-completed', 'wc-cancelled', 'wc-pending', 'wc-failed') );
$result = $wpdb->get_results( "SELECT * FROM $wpdb->posts
WHERE post_type = 'shop_order'
AND post_status IN ('{$post_status}')
AND post_date BETWEEN '{$date_from} 00:00:00' AND '{$date_to} 23:59:59'
");
Here is the order data and within the loop we can find the payment method of that order so we can start an inner loop with the payment gateway method and can print it with a table.
If you need any custom woocommerce plugin development or any woocommerce customization please contact me. I’ll be happy to help you.