1. Let’s start by creating a new WordPress and Laravel integration from WordPress Pete.

2. For this tutorial, we will use Laravel 8, and the name of our Laravel app will be woodashboard. You must have previously imported a WordPress site.

3. We can verify everything is OK by clicking on the link to see the examples.

4. After this, it is a good idea to familiarize yourself with the structure of how your files look. Open the WordPress Pete installation folder with your favorite text editor. Since I am old school, I use TextMate.

  • The WordPress Pete installation folder name is saveaplaya
  • The name of the WordPress site folder is saveaplayapetelocalnet
  • The name of the Laravel app integrated into WordPress is woodashboard
  • Inside woodasboard you can find all the files of the Laravel app.

The integration Pete does of WordPress and Laravel is clean. That means all WordPress and Laravel files are complete, and you can update each app to its latest versions without breaking the integration. Cool right?

5. To create a controller in Laravel from the terminal, you must enter the apache container in docker. For this, go to the installation guide of your operating system and copy the command to enter the apache container in docker.

6. Now, browse the Laravel app folder and run the command to create a controller.

php artisan make:controller WooDashboard

After this, we copy and paste this code into our WooDashboard controller.

woodashboard/app/Http/Controllers/WooDashboard.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
//add this
use Illuminate\Support\Facades\Config;

class WooDashboard extends Controller
{
    //add this
	public function orders(){
	
	$db_config = Config::get('database.connections.'.Config::get('database.default'));

	$mysqli = new \mysqli($db_config["host"], $db_config["username"], $db_config["password"], $db_config["database"]);

	if ($mysqli->connect_errno) {
	    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
	}
	
	$query = "select
    p.ID as order_id,
    p.post_date,
    max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
    max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
    max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
    max( CASE WHEN pm.meta_key = '_billing_address_1' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_1,
    max( CASE WHEN pm.meta_key = '_billing_address_2' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_2,
    max( CASE WHEN pm.meta_key = '_billing_city' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_city,
    max( CASE WHEN pm.meta_key = '_billing_state' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_state,
    max( CASE WHEN pm.meta_key = '_billing_postcode' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_postcode,
    max( CASE WHEN pm.meta_key = '_shipping_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_first_name,
    max( CASE WHEN pm.meta_key = '_shipping_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_last_name,
    max( CASE WHEN pm.meta_key = '_shipping_address_1' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_address_1,
    max( CASE WHEN pm.meta_key = '_shipping_address_2' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_address_2,
    max( CASE WHEN pm.meta_key = '_shipping_city' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_city,
    max( CASE WHEN pm.meta_key = '_shipping_state' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_state,
    max( CASE WHEN pm.meta_key = '_shipping_postcode' and p.ID = pm.post_id THEN pm.meta_value END ) as _shipping_postcode,
    max( CASE WHEN pm.meta_key = '_order_total' and p.ID = pm.post_id THEN pm.meta_value END ) as order_total,
    max( CASE WHEN pm.meta_key = '_order_tax' and p.ID = pm.post_id THEN pm.meta_value END ) as order_tax,
    max( CASE WHEN pm.meta_key = '_paid_date' and p.ID = pm.post_id THEN pm.meta_value END ) as paid_date,
	max( CASE WHEN pm.meta_key = '_customer_user' and p.ID = pm.post_id THEN pm.meta_value END ) as customer_user,
	
    ( select group_concat( order_item_name separator '|' ) from wp_woocommerce_order_items where order_id = p.ID ) as order_items
	from
    	wp_posts p 
    	join wp_postmeta pm on p.ID = pm.post_id 
   	 	join wp_woocommerce_order_items oi on p.ID = oi.order_id
	where
    	p.post_type = 'shop_order' and
    	p.post_date BETWEEN '2022-10-01' AND '2022-12-31' and
   	 	p.post_status = 'wc-completed'
	group by
    p.ID";
	
	$result = $mysqli->query($query);

	return view('WooDashboard.orders',compact('result'));
	
	}
}

7. Now we create the Laravel view 

woodashboard/resources/views/WooDashboard/orders.blade.php

<html>

	<head>
		
		<!-- CSS -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

		<!-- jQuery and JS bundle w/ Popper.js -->
		<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
		
	</head>

    <body>

		<div class="container">
			
			<br />		
			 <h3>All completed orders</h3>  
			 
			 
			
				
	  		  <table class="table table-hover">
				  
	  		    <thead>
	  		      <tr>
					<th>order_id</th>
	  		        <th>billing_first_name</th>
	  		        <th>billing_email</th>
	  		        <th>order_total</th>
	  		      </tr>
	  		    </thead>
	  		    
				<tbody>
					
					@while($row = $result->fetch_assoc()) 
					
  	  		      <tr>
  	  		        <td>{{$row["order_id"]}}</td>
					<td>{{$row["_billing_first_name"]}}</td>
  	  		        <td>{{$row["billing_email"]}}</td>
  	  		        <td>{{$row["order_total"]}}</td>
  	  		      </tr>
				  
				  	@endwhile
				
				 </tbody> 
  	
			</table>
		
		</div>
		
    </body>
</html>

8. Now we declare the route for this action

woodashboard/routes/web.php

<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\HelloController;  
//add this
use App\Http\Controllers\WooDashboard;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('list_users', [HelloController::class,'list_users']);
Route::get('list_orders', [HelloController::class,'list_orders']);
Route::get('list_posts', [HelloController::class,'list_posts']);
Route::get('list_products', [HelloController::class,'list_products']);
Route::get('edit_posts', [HelloController::class, 'edit_posts']);
Route::get('edit_post', [HelloController::class, 'edit_post']);
Route::post('update_post', [HelloController::class, 'update_post']);
Route::get('/wordpress_plus_laravel_examples', [HelloController::class, 'wordpress_plus_laravel_examples']);

//add this
Route::get('orders', [WooDashboard::class, 'orders']);

9. Now we can see the list of woocommerce orders from Laravel

Latest tutorials

Deploy a WordPress Laravel Integration using Pete’s superpowers

Let's start this tutorial after having done this: Handling woocommerce orders from Laravel using Pete’s superpowersThen migrate our saveaplaya site to a WordPress Pete in production. To know how to do this, read this tutorial: Migrate your WordPress site to the cloud...

Hardening your WordPress site with WordPress Pete and Mod Security

WordPress Pete with coreruleset v3.3 out of the box and other good practices. You won't have to worry about most hack attacks. You can also disable or enable the mod_security firewall at your convenience if you are developing any feature of your site to avoid false...

Install a SSL certificate to a WordPress site using WordPress Pete

For this example we will use the domain wordpresspete.org which is pointing to a WordPress Pete installation. To see how to do this check out this tutorial: Point a domain to a WordPress Pete in production environment1. For this example we purchased an SSL certificate...

Migrate your WordPress site to the cloud using WordPress Pete

For this example we will use the domain peteteting.com which is pointing to a WordPress Pete installation. To see how to do this check out this tutorial: Point a domain to a WordPress Pete in production environment1. Using the input file1. Check that the domain you...

Point a domain to a WordPress Pete in production environment

Let's start by following the tutorial for installing WordPress Pete on Google Cloud Platform.Once you have installed WordPress Pete correctly go to the settings panel of your domain provider, for this example we will use a godaddy.com domainUse your domain provider's...

Create a WordPress + Laravel integration using a subdomain

1. Make sure you have imported your site into WordPress Pete correctly. For this example, we will use the saveaplaya.org site2. Lets browse to the Premium plugins section and let's download the plugin, then we will install it on the site3. Now we will activate the...

Create a WordPress + Laravel integration in the same domain

1. Make sure you have imported your site into WordPress Pete correctly. For this example, we will use the saveaplaya.org site2. We will make sure that we have the WordPress + Laravel plugin for WordPress Pete installed. You must have the standard license to be able to...

Create a WordPress Pete file manually

To create a WordPress Pete we need three files: the website folder, the database in a SQL file and the file config.txt For this example, we are going to create the WordPress Pete manually file for the nostalgiosity.com site. 1. We are going to use the file manager of...

Register your WordPress Pete

To register your Premium license of WordPress Pete Click here to go to the pricing page and click button “Buy Now” Below Premium License.2. Once you have purchased the premium membership and have logged into your account. Click on the API Key Generator option that...

Migrate a WordPress site to WordPress Pete

1.  Log into your WordPress Pete installation and click on the "Plugins" section. Then click the "Download Pete Converter" button.2. Once you download the plugin, go to your WordPress admin panel and install it. 3. Go to the Pete Converter option on your admin and...

Author: Pedro Consuegra

Full Stack Software Developer with expertise in WordPress, Laravel, Ruby, Ruby on Rails, JavaScript, and MySQL. Dedicated to empowering small to medium-sized businesses in realizing their IT objectives, with a proven track record of reducing engineering costs by up to 90%.