This package allows users to easily consume the REST API provided by automattic/woocommerce in any Laravel app.
The recommended way to install WooCommerce-API is through Composer.
composer require c14r/woocommerce-api
WOOCOMMERCE_URL=https://www.your-shop.com/
WOOCOMMERCE_KEY=ck_???
WOOCOMMERCE_SECRET=cs_???
WOOCOMMERCE_VERSION=wc/v3
If you want to change the default configuration or you want to use multiple connection you can publish the config/woocommerce.php
by ``php artisan vendor:publish --tag=woocommerce-config`
- WooCommerce API Wrapper for PHP
- ToDos
- Usage
- Services Classes
- API
The documentation ist still not complete.
https://vendidero.de/dokument/shipments-rest-api
- Shipments
- Cancellations
- Invoices
use C14r\Woocommerce\V3\API;
// via helper function
$api = woo();
// via dependency injection
public function example(API $api)
// via singleton
$api = API::getInstance();
Every get()
or all()
request can be cached, you just need to call the cache()
or cacheAll()
methods.
$order = $api->order($order_id)->cache(); // instead of ...->get()
$orders = $api->orders()->cacheAll(); // instead of ...->all()
Instead of calling ->per_page(25)->page($page)->get()
or ->all()
you can use the default laravel pagination. For more information see the Laravel Docs.
$orders = $api->paginate();
Service classes simplify API usage by wrapping API calls into specialized methods, improving code readability, maintainability, and reducing API interaction complexity.
$service->increseStockQuantity(int $product_id, int $amount = 1);
$service->decreseStockQuantity(int $product_id, int $amount = 1);
$service->setStockQuantity(int $product_id, int $stock_quantity);
$service->getStockQuantity(int $product_id);
$service->setStatus(int $product_id, ProductStatus $status);
$service->rename(int $product_id, string $name);
$service->get(int $product_id);
$service->update(int $product_id, array $data);
$service->get(int $order_id);
$service->getWithCustomer(int $order_id);
// List Coupons
$api->coupons()->get();
// Retrieve an Coupon
$api->coupon($coupon_id)->get();
// Create an Coupon
$api->coupons()->create([
'code' => '10off',
'discount_type' => CouponsDiscountType::percent,
'amount' => 10,
'individual_use' => true,
'exclude_sale_items' => true,
'minimum_amount' => 100.00
]);
// Update an Coupon
$api->coupon($coupon_id)->update([
'amount' => 5
]);
// Delete an Coupon
$api->coupon($coupon_id)->delete();
// Batch
$api->couponBatch()->post([
'create' => [
[
'code' => '20off',
'discount_type' => CouponsDiscountType::percent,
'amount' => 20,
'individual_use' => true,
'exclude_sale_items' => true,
'minimum_amount' => 100.00
],
[
'code' => '30off',
'discount_type' => CouponsDiscountType::percent,
'amount' => 30,
'individual_use' => true,
'exclude_sale_items' => true,
'minimum_amount' => 100.00
]
],
'update' => [
[
'id' => 719,
'minimum_amount' => 50.00
]
],
'delete' => [
720
]
]);
// List Customers
$api->customers()->get();
// Retrieve a Customer
$api->customer($customer_id)->get();
// Create a Customer
$api->customers()->create([
]);
// Update a Customer
$api->customer($customer_id)->update([
]);
// Batch
$api->customerBatch()->post([
]);
// Retrieve Customer Downloads
$api->customerDownloads($customer_id)->get();
// List Orders (paginated)
$api->orders()->get();
// List all Orders
$api->orders()->all(); // or cacheAll($seconds)
// Retrieve an Order
$api->order($order_id)->get();
// Create an Order
$api->orders()->create([
'title' => 'The Title!',
'status' => OrderStatus::on_hold
]);
// Update an Order
$api->order($id)->update([
'status' => OrderStatus::completed
]);
// Delete an order
$api->order($id)->delete();
// List Order Notes per Order
$api->orderNotes($order_id)->get();
// Retrieve an Order Note
$api->orderNote($order_id, $note_id)->get();
// Create an Order Note
$api->orderNotes($order_id)->create([
'note' => 'Order ok!'
]);
// Delete an Order Note
$api->orderNote($order_id, $note_id)->delete();
// List Order Refunds per Order
$api->orderRefunds($order_id)->get();
// Retrieve an Order Refund
$api->orderRefund($order_id, $refund_id)->get();
// Create an Order Refund
$api->orderRefunds($order_id)->create([
'amount' => 30,
'line_items' => [
[
'id' => 111,
'refund_total' => 10,
'refund_tax' => [
[
'id' => 222,
'amount' => 20
]
]
]
]
]);
// Delete an Order Refund
$api->orderRefund($order_id, $refund_id)->delete();
// List Product
$api->products()->get();
// Retrieve a Product
$api->product($product_id)->get();
// Create a Product
$api->product($product_id)->create([
'name' => 'Premium Quality',
'type' => 'simple',
'regular_price' => 21.99,
'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
'categories' => [
[
'id' => 9
],
[
'id' => 14
]
],
'images' => [
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg'
],
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg'
]
]
]);
// Update a Product
$api->product($product_id)->update([
'regular_price' => 24.54
]);
// Batch
$api->productBatch()->post([
'create' => [
[
'name' => 'Woo Single #1',
'type' => ProductType::simple,
'regular_price' => 21.99,
'virtual' => true,
'downloadable' => true,
'downloads' => [
[
'name' => 'Woo Single',
'file' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg'
]
],
'categories' => [
[
'id' => 11
],
[
'id' => 13
]
],
'images' => [
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg'
]
]
],
[
'name' => 'New Premium Quality',
'type' => 'simple',
'regular_price' => 21.99,
'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
'categories' => [
[
'id' => 9
],
[
'id' => 14
]
],
'images' => [
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg'
],
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg'
]
]
]
],
'update' => [
[
'id' => 799,
'default_attributes' => [
[
'id' => 6,
'name' => 'Color',
'option' => 'Green'
],
[
'id' => 0,
'name' => 'Size',
'option' => 'M'
]
]
]
],
'delete' => [
794
]
]);
// List Product Attributes
$api->productAttributes()->get();
// Retrieve a Product Attributes
$api->productAttribute($attribute_id)->get();
// Create a Product Attributes
$api->productAttributes()->create([
'name' => 'Color',
'slug' => 'pa_color',
'type' => AttributesType::select,
'order_by' => OrderByAttributes::menu_order,
'has_archives' => true
]);
// Update a Product Attributes
$api->productAttribute($attribute_id)->update([
'order_by' => OrderByAttributes::name,
]);
// Batch
$api->productAttributeBatch()->post([
'create' => [
[
'name' => 'Brand'
],
[
'name' => 'Publisher'
]
],
'update' => [
[
'id' => 2,
'order_by' => 'name'
]
],
'delete' => [
1
]
]);
// List Product Attribute Terms
$api->productAttributeTerms($attribute_id)->get();
// Retrieve a Product Attribute Terms
$api->productAttributeTerm($attfibute_id, $term_id)->get();
// Create a Product Attribute Terms
$api->productAttributeTerms($attfibute_id)->create([
'name' => 'XXS'
]);
// Update a Product Attribute Terms
$api->productAttributeTerm($attfibute_id, $term_id)->update([
'name' => 'XXS'
]);
// Batch
$api->productAttributeTermBatch()->post([
'create' => [
[
'name' => 'XXS'
],
[
'name' => 'S'
]
],
'update' => [
[
'id' => 19,
'menu_order' => 6
]
],
'delete' => [
21,
20
]
]);
// List Product Categories
$api->productCategories()->get();
// Retrieve a Product Categories
$api->productCategory($category_id)->get();
// Create a Categories
$api->productCategories()->create([
'name' => 'Clothing',
'image' => [
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg'
]
]);
// Update a Categories
$api->productCategory($category_id)->update([
'description' => 'All kinds of clothes.'
]);
// Batch
$api->productCategoryBatch()->post([
'create' => [
[
'name' => 'Albums'
],
[
'name' => 'Clothing'
]
],
'update' => [
[
'id' => 10,
'description' => 'Nice hoodies'
]
],
'delete' => [
11,
12
]
]);
// List Product Reviews
$api->productReviews($product_id)->get();
// Retrieve a Product Reviews
$api->productReview($product_id, $review_id)->get();
// Create a Product Reviews
$api->productReviews($product_id)->create([
'product_id' => 22,
'review' => 'Nice album!',
'reviewer' => 'John Doe',
'reviewer_email' => 'john.doe@example.com',
'rating' => 5
]);
// Update a Product Reviews
$api->productReview($product_id, $review_id)->update([
'rating': 5
]);
// Batch
$api->productReviewBatch($product_id)->post([
'create' => [
[
'product_id' => 22,
'review' => 'Looks fine',
'reviewer' => 'John Doe',
'reviewer_email' => 'john.doe@example.com',
'rating' => 4
],
[
'product_id' => 22,
'review' => 'I love this album',
'reviewer' => 'John Doe',
'reviewer_email' => 'john.doe@example.com',
'rating' => 5
]
],
'update' => [
[
'id' => 7,
'reviewer' => 'John Doe',
'reviewer_email' => 'john.doe@example.com',
]
],
'delete' => [
22
]
]);
// List Product Tags
$api->productTags()->get();
// Retrieve a Product Tags
$api->productTag($tag_id)->get();
// Create a Product Tags
$api->productTags()->create([
'name' => 'Leather Shoes'
]);
// Update a Product Tags
$api->productTag($tag_id)->update([
'description': 'Genuine leather.'
]);
// Batch
$api->productTagBatch()->post([
'create' => [
[
'name' => 'Round toe'
],
[
'name' => 'Flat'
]
],
'update' => [
[
'id' => 34,
'description' => 'Genuine leather.'
]
],
'delete' => [
35
]
]);
// List Product Variations
$api->productVariations($product_id)->get();
// Retrieve a Product Variations
$api->productVariation($product_id, $variation_id)->get();
// Create a Product Variations
$api->productVariation($product_id)->create([
'regular_price' => 9.00,
'image' => [
'id' => 423
],
'attributes' => [
[
'id' => 9,
'option' => 'Black'
]
]
]);
// Update a Product Variations
$api->productVariation($product_id, $variation_id)->update([
'regular_price' => 10.00
]);
// Batch
$api->productVariationsBatch($product_id)->post([
'create' => [
[
'regular_price' => 10.00,
'attributes' => [
[
'id' => 6,
'option' => 'Blue'
]
]
],
[
'regular_price' => 10.00,
'attributes' => [
[
'id' => 6,
'option' => 'White'
]
]
]
],
'update' => [
[
'id' => 733,
'regular_price' => 10.00
]
],
'delete' => [
732
]
]);
// List Shipping Methods
$api->shippingMethods()->get();
// Retrieve a Shipping Methods
$api->shippingMethod($method_id)->get();
// Create a Shipping Methods
$api->shippingMethods()->create([
]);
// Update a Shipping Methods
$api->shippingMethod($method_id)->update([
]);
// List Shipping Zones
$api->shippingZones()->get();
// Retrieve a Shipping Zones
$api->shippingZone($zone_id)->get();
// Create a Shipping Zones
$api->shippingZones()->create([
]);
// Update a Shipping Zones
$api->shippingZone($zone_id)->update([
]);
// TODO
// List Shipping Zones Method
$api->shippingZoneMethods($zone_id)->get();
// Retrieve a Shipping Zones Method
$api->shippingZoneMethod($zone_id, $instance_id)->get();
// Create a Shipping Zones Method
$api->shippingZoneMethods($zone_id)->create([
]);
// Update a Shipping Zones Method
$api->shippingZoneMethod($zone_id, $instance_id)->update([
]);
// List Reports
$api->reports()->get();
// List Report Sales
$api->xyz()->get();
// Retrieve a Report Sales
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List Report Top Seller
$api->xyz()->get();
// Retrieve a Report Top Seller
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List ettings
$api->xyz()->get();
// Retrieve a ettings
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List axes
$api->xyz()->get();
// Retrieve a axes
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List Tax Classes
$api->xyz()->get();
// Retrieve a Tax Classes
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List ebhooks
$api->xyz()->get();
// Retrieve a ebhooks
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List ayment Gateways
$api->xyz()->get();
// Retrieve a ayment Gateways
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List ystem
$api->xyz()->get();
// Retrieve a ystem
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List System Status
$api->xyz()->get();
// Retrieve a System Status
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);
// List System Status Tools
$api->xyz()->get();
// Retrieve a System Status Tools
$api->xyz()->get();
// Create a xyz
$api->xyz()->create([
]);
// Update a xyz
$api->xyz()->update([
]);
// Batch
$api->xyz()->post([
]);