boukjijtarik/woo-sales-report

A Laravel package to fetch WooCommerce orders using database queries and display them in views

dev-main 2025-06-25 00:06 UTC

This package is auto-updated.

Last update: 2025-06-25 00:06:56 UTC


README

A Laravel 12 package to fetch WooCommerce orders directly from the database using queries (not API) and display them in beautiful, responsive views.

Features

  • 🔍 Direct Database Queries: Fetch orders directly from WooCommerce database tables
  • 📊 Comprehensive Order Data: Get complete order details including items, customer info, and shipping
  • 🎨 Beautiful UI: Bootstrap-styled responsive views
  • 🔧 Highly Configurable: Customize database connections, table names, and order statuses
  • 📄 Pagination: Built-in pagination for large order lists
  • 🎯 Filtering: Filter orders by status, date range, customer email, and amount
  • 📈 Sales Summary: Get sales statistics and summaries

Requirements

  • PHP 8.1 or higher
  • Laravel 12.x
  • WooCommerce database access
  • MySQL/MariaDB database

Installation

1. Install via Composer

composer require boukjijtarik/woo-sales-report

2. Publish Configuration

php artisan vendor:publish --tag=woo-sales-report-config

3. Publish Views (Optional)

If you want to customize the views:

php artisan vendor:publish --tag=woo-sales-report-views

Configuration

Database Setup

Add your WooCommerce database connection to config/database.php:

'connections' => [
    // ... other connections
    
    'woocommerce' => [
        'driver' => 'mysql',
        'host' => env('WOO_DB_HOST', '127.0.0.1'),
        'port' => env('WOO_DB_PORT', '3306'),
        'database' => env('WOO_DB_DATABASE', 'woocommerce_db'),
        'username' => env('WOO_DB_USERNAME', 'root'),
        'password' => env('WOO_DB_PASSWORD', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => env('WOO_DB_PREFIX', 'wp_'),
        'strict' => true,
        'engine' => null,
    ],
],

Environment Variables

Add these to your .env file:

# WooCommerce Database
WOO_DB_CONNECTION=woocommerce
WOO_DB_HOST=127.0.0.1
WOO_DB_PORT=3306
WOO_DB_DATABASE=your_woocommerce_db
WOO_DB_USERNAME=your_username
WOO_DB_PASSWORD=your_password
WOO_DB_PREFIX=wp_

# Package Configuration
WOO_REPORTS_PER_PAGE=25
WOO_DATE_FORMAT=d/m/Y
WOO_CURRENCY=USD
WOO_CURRENCY_SYMBOL=$

Package Configuration

The published config file (config/woo-sales-report.php) allows you to customize:

  • Database connection and table names
  • Order statuses to include in reports
  • Pagination settings
  • Date format
  • Currency settings

Usage

Routes

The package automatically registers these routes:

  • GET /woo-sales-report/orders - List all orders
  • GET /woo-sales-report/orders/{order_id} - View specific order details

Basic Usage

List Orders

use BoukjijTarik\WooSalesReport\Services\WooCommerceOrderService;

$orderService = new WooCommerceOrderService();
$orders = $orderService->getOrders(25); // 25 orders per page

Get Specific Order

$order = $orderService->getOrderById(123);

Get Order Items

$orderItems = $orderService->getOrderItems(123);

Get Sales Summary

$summary = $orderService->getSalesSummary('2024-01-01', '2024-12-31');

Filtering Orders

$filters = [
    'status' => 'wc-completed',
    'start_date' => '2024-01-01',
    'end_date' => '2024-12-31',
    'customer_email' => 'customer@example.com',
    'min_amount' => 100,
    'max_amount' => 1000,
];

$orders = $orderService->getOrders(25, $filters);

Using in Controllers

<?php

namespace App\Http\Controllers;

use BoukjijTarik\WooSalesReport\Services\WooCommerceOrderService;
use Illuminate\Http\Request;

class SalesController extends Controller
{
    protected $orderService;

    public function __construct(WooCommerceOrderService $orderService)
    {
        $this->orderService = $orderService;
    }

    public function index(Request $request)
    {
        $orders = $this->orderService->getOrders(
            $request->input('per_page', 25),
            $request->only(['status', 'start_date', 'end_date', 'customer_email'])
        );

        return view('sales.index', compact('orders'));
    }

    public function show($orderId)
    {
        $order = $this->orderService->getOrderById($orderId);
        
        if (!$order) {
            abort(404);
        }

        return view('sales.show', compact('order'));
    }
}

Using in Blade Views

@extends('layouts.app')

@section('content')
<div class="container">
    <h1>Sales Report</h1>
    
    @foreach($orders as $order)
        <div class="card mb-3">
            <div class="card-body">
                <h5 class="card-title">Order #{{ $order->order_id }}</h5>
                <p class="card-text">
                    <strong>Date:</strong> {{ $order->order_date }}<br>
                    <strong>Customer:</strong> {{ $order->billing_first_name }} {{ $order->billing_last_name }}<br>
                    <strong>Total:</strong> {{ $order->total_amount }}<br>
                    <strong>Status:</strong> {{ $order->order_status }}
                </p>
                <a href="{{ route('woo-sales-report.orders.show', $order->order_id) }}" 
                   class="btn btn-primary">View Details</a>
            </div>
        </div>
    @endforeach
    
    {{ $orders->links() }}
</div>
@endsection

Customization

Custom Order Statuses

Edit config/woo-sales-report.php to include your custom order statuses:

'order_statuses' => [
    'wc-completed',
    'wc-processing',
    'wc-custom-status',
    // Add your custom statuses here
],

Custom Table Names

If your WooCommerce installation uses different table names:

'tables' => [
    'posts' => 'custom_posts_table',
    'postmeta' => 'custom_postmeta_table',
    'order_items' => 'custom_order_items_table',
    'order_itemmeta' => 'custom_order_itemmeta_table',
    // ... other tables
],

Custom Views

After publishing views, you can customize them in resources/views/vendor/woo-sales-report/.

Troubleshooting

Common Issues

  1. Database Connection Error

    • Verify your WooCommerce database credentials
    • Check if the database connection is properly configured
    • Ensure the database user has proper permissions
  2. No Orders Found

    • Check if the table prefix is correct
    • Verify that order statuses in config match your WooCommerce statuses
    • Ensure orders exist in the database
  3. Permission Denied

    • Make sure the database user has SELECT permissions on WooCommerce tables

Debug Mode

Enable debug mode in your .env file to see detailed error messages:

APP_DEBUG=true

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This package is open-sourced software licensed under the MIT license.

Support

For support, please open an issue on GitHub or contact us at contact@boukjijtarik.com.

Changelog

v1.0.0

  • Initial release
  • Basic order listing and details
  • Database query support
  • Bootstrap-styled views
  • Configuration system