Coming Soon

Woocommerce + Laravel

Using woocommerce as a headless e-commerce app with laravel as a middleware powered with corcel

Sometime back I needed to upgrade a woocommerce site to laravel so I could build custom features using laravel while allowing the admins to continue using the platform they were used to. Initially I thought of using wordpress's rest api but that would mean adding new features to wordpress which I wanted to moving away from. That's when I stumbled onto corcel package.

Corcel is a collection of PHP classes built on top of Eloquent ORM (from Laravel framework), that provides a fluent interface to connect and get data directly from a WordPress database.

With Corcel you can use eloquent to access Posts/Pages, Taxonomies, Metadata the same way you would any other eloquent Model. Got a custom post type, no problem just create a new model extending Post and set the postType to the custom post type. Corcel even includes packages for woocommerce and Advanced Custom Fields (ACF). In case you are using a custom plugin that stores data in a different table, you can create you own model to retrieve the data using these packages as guides.

Today I'll share the process I took and some of the caveats I had to deal with. The assumption is you have a wordpress based website with woocommerce and ACF.

https://woocommerce.github.io/woocommerce-rest-api-docs/#introduction

Steps

Setup a wordpress / woocommerce app

Skip if you already have a wordpress installation.

  1. Install new project using bedrock
composer create-project roots/bedrock
  1. Update .env file, generate salts
  2. Complete WP setup
  3. Install Woocommerce
composer require wpackagist-plugin/woocommerce

4.2 Activate WooCommerce plugin 4.3 Setup WooCommerce 4.4 Import products sample data https://woocommerce.com/document/importing-woocommerce-sample-data/ large data set: https://glover.us/blog/woocommerce-sample-data-set/