1. Go to this page and download the library: Download albertvds/laravel-wp-sync library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
albertvds / laravel-wp-sync example snippets
use Albertvds\WpSync\WpFacade as Wp;
// Fetch published posts
Wp::posts()->where('status', 'publish')->get();
// Fetch posts in a category, paginated
Wp::posts()->where('status', 'publish')->category('news')->paginate(10);
// Fetch a single post by slug
Wp::posts()->slug('my-post-slug')->first();
// Search posts
Wp::posts()->search('laravel')->get();
// Fetch pages
Wp::pages()->where('status', 'publish')->get();
// Fetch categories
Wp::categories()->get();
// Fetch media
Wp::media()->get();
use Albertvds\WpSync\WooFacade as Woo;
// Fetch all processing orders
Woo::orders()->where('status', 'processing')->get();
// Fetch orders placed after a date, paginated
Woo::orders()->where('status', 'processing')->after('2024-01-01')->paginate(20);
// Fetch a single order by ID
Woo::orders()->find(42);
// Fetch in-stock products
Woo::products()->inStock()->get();
// Search products
Woo::products()->search('t-shirt')->paginate(15);
// Fetch customers
Woo::customers()->get();
// Fetch coupons
Woo::coupons()->get();
// Fetch product categories
Woo::categories()->get();
use Albertvds\WpSync\Events\OrderCreated;
use Albertvds\WpSync\Events\OrderUpdated;
use Albertvds\WpSync\Events\ProductUpdated;
use Albertvds\WpSync\Events\CustomerCreated;
// In EventServiceProvider or using #[AsEventListener]
Event::listen(OrderCreated::class, function (OrderCreated $event) {
// $event->order is a typed WooOrder DTO
Mail::to($event->order->billingEmail)
->send(new OrderConfirmationMail($event->order));
});
Event::listen(ProductUpdated::class, function (ProductUpdated $event) {
// $event->product is a typed WooProduct DTO
Cache::forget('product-'.$event->product->id);
});
use Albertvds\WpSync\Events\WooWebhookReceived;
Event::listen(WooWebhookReceived::class, function (WooWebhookReceived $event) {
Log::info('Webhook received', [
'topic' => $event->topic,
'payload' => $event->payload,
]);
});