This document is written for WooCommerce developers looking to extend or customize WooCommerce Composite Products. It requires an advanced understanding of PHP and WordPress development.
WooCommerce 2.6 added support for REST API endpoints based on the WordPress REST API infrastructure.
Composite Products extends the /products/ and /orders/ endpoint responses with additional properties that are documented in this guide.
Products ↑ Back to top
Product Properties ↑ Back to top
Attribute | Type | Context | Description |
---|---|---|---|
composite_layout |
string |
read write |
Single-product template layout. Applicable to composite-type products. Values: single , progressive , paged , paged-componentized . |
composite_add_to_cart_form_location |
string |
read write |
Controls the form location of the product in the single-product page. Values: default , after_summary . |
composite_editable_in_cart |
bool |
read write |
Controls whether the configuration of this product can be modified from the cart page. |
composite_sold_individually_context |
string |
read write |
Sold Individually option context. Values: product , configuration . |
composite_shop_price_calc |
string |
read write |
Composite catalog price calculation type. Values: defaults , min_max , hidden . |
composite_components |
array |
read write |
List of components that this product consists of. Applicable to composite-type products. See Component Properties. |
composite_scenarios |
array |
read write |
Scenarios configured for this product. Applicable to composite-type products. See Scenario Properties. |
Component Properties
Attribute | Type | Context | Description |
---|---|---|---|
id |
string |
read |
Component ID. |
delete |
boolean |
write |
Set to true to delete the component with the specified ID. |
title |
string |
read write |
Title of the component. |
description |
string |
read write |
Description of the component. |
query_type |
string |
read write |
Component options query type. Values: product_ids , category_ids . |
query_ids |
array( int ) |
read write |
Product IDs or category IDs to use for populating component options. |
default_option_id |
integer |
read write |
The product ID of the default/pre-selected component opion. |
thumbnail_id |
integer |
read write |
The attachment ID of the thumbnail associated with this Component. |
thumbnail_src |
string |
read write |
URL of the thumbnail associated with this Component. |
quantity_min |
integer |
read write |
Minimum component quantity. |
quantity_max |
integer |
read write |
Maximum component quantity. |
priced_individually |
boolean |
read write |
Indicates whether the price of this component is added to the base price of the composite. |
shipped_individually |
boolean |
read write |
Indicates whether this component is shipped separately from the composite. |
optional |
boolean |
read write |
Indicates whether the component is optional. |
discount |
string |
read write |
Discount applied to the component, applicable when the Priced Individually option is enabled. |
options_style |
string |
read write |
Indicates which template/style to use to display component options. Values: dropdowns , thumbnails , radios . |
pagination_style |
string |
read write |
Controls how new Thumbnails are loaded into the Component Options view. Applicable when the Options Style of this Component is set to Thumbnails. Values: classic , load-more . |
display_prices |
string |
read write |
Controls how Component Option prices are displayed. Applicable when Priced Individually is enabled for this Component. Values: absolute , relative , hidden . |
show_sorting_options |
boolean |
read write |
Whether to display sorting options in this Component. |
show_filtering_options |
boolean |
read write |
Whether to display filtering options in this Component. |
attribute_filter_ids |
array( int ) |
read write |
Attribute IDs to use for creating Component Option filters. |
product_title_visible |
boolean |
read write |
Controls the visibility of product titles in the Component Selection view. |
product_descr_visible |
boolean |
read write |
Controls the visibility of product short descriptions in the Component Selection view. |
product_price_visible |
boolean |
read write |
Controls the visibility of product prices in the Component Selection view. |
product_thumb_visible |
boolean |
read write |
Controls the visibility of product thumbnails in the Component Selection view. |
subtotal_visible_product |
boolean |
read write |
Controls the visibility of the subtotal associated with this Component in the single-product page. |
subtotal_visible_cart |
boolean |
read write |
Controls the visibility of the subtotal associated with this Component in the cart page. |
subtotal_visible_orders |
boolean |
read write |
Controls the visibility of the subtotal associated with this Component in order-related pages and e-mail notifications. |
Scenario Properties
Attribute | Type | Context | Description |
---|---|---|---|
id |
string |
read |
Scenario ID. |
delete |
boolean |
write |
Set to true to delete the scenario with the specified ID. |
name |
string |
read write |
Name of the scenario. |
description |
string |
read write |
Optional short description of the scenario. |
configuration |
array |
read write |
Matching conditions for components. See Component Matching Condition Properties. |
actions |
array |
read write |
Scenario actions. See Scenario Action Properties. |
Component Matching Condition Properties
Attribute | Type | Context | Description |
---|---|---|---|
component_id |
string |
read write |
Component ID. |
component_options |
array |
read write |
Product/variation IDs in component targeted by the scenario (0 = any product or variation, -1 = no selection). |
options_modifier |
string |
read write |
Comparison modifier for the referenced product/variation IDs. Values: in , not-in , masked . |
Scenario Action Properties
Attribute | Type | Context | Description |
---|---|---|---|
scenario_id |
string |
read write |
Scenario action ID (by default compat_group or conditional_components ). |
is_active |
boolean |
read write |
Indicates whether the scenario action is active. |
action_data |
object |
read write |
Custom action data. |
Working with Products: Examples ↑ Back to top
Create Composite
curl -X POST https://example.com/wp-json/wc/v2/products \ | |
-u consumer_key:consumer_secret \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"name": "Build Your Ninja Outfit", | |
"type": "composite", | |
"description": "In pretium enim justo, at ornare libero aliquam quis. Nullam imperdiet rutrum volutpat. Suspendisse aliquet ex in ex volutpat vestibulum. Curabitur ultrices convallis condimentum.", | |
"short_description": "In pretium enim justo, at ornare libero aliquam quis.", | |
"categories": [ | |
{ | |
"id": 9 | |
} | |
], | |
"images": [ | |
{ | |
"src": "https://www.somewherewarm.net/cp/woo/wp-content/uploads/Ninja_bundle.jpg", | |
"position": 0 | |
} | |
], | |
"composite_components": [ | |
{ | |
"title": "Your Ninja Tee", | |
"description": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.", | |
"query_type": "category_ids", | |
"query_ids": [ 14 ], | |
"quantity_min": 1, | |
"quantity_max": 1, | |
"priced_individually": true, | |
"shipped_individually": false, | |
"optional": false, | |
"discount": "20.0", | |
"options_style": "thumbnails" | |
}, | |
{ | |
"title": "Your Ninja Hoodie", | |
"description": "Nullam imperdiet rutrum volutpat. Suspendisse aliquet ex in ex volutpat vestibulum. Curabitur ultrices convallis condimentum.", | |
"query_type": "category_ids", | |
"query_ids": [ 10 ], | |
"quantity_min": 1, | |
"quantity_max": 1, | |
"priced_individually": true, | |
"shipped_individually": false, | |
"optional": false, | |
"discount": "20.0", | |
"options_style": "thumbnails" | |
} | |
], | |
"composite_layout": "single" | |
}' |
Add Component
curl -X PUT https://example.com/wp-json/wc/v2/products/133 \ | |
-u consumer_key:consumer_secret \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"composite_components": [ | |
{ | |
"title": "Your Free Poster", | |
"description": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.", | |
"query_type": "product_ids", | |
"query_ids": [ 70 ], | |
"quantity_min": 1, | |
"quantity_max": 1, | |
"priced_individually": true, | |
"shipped_individually": true, | |
"optional": false, | |
"discount": "100.0", | |
} | |
] | |
}' |
Modify Component
curl -X PUT https://example.com/wp-json/wc/v2/products/133 \ | |
-u consumer_key:consumer_secret \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"composite_components": [ | |
{ | |
"id": "123456789", | |
"title": "Your Poster Offer", | |
"optional": true, | |
"discount": "50.0", | |
} | |
] | |
}' |
Delete Component
curl -X PUT https://example.com/wp-json/wc/v2/products/133 \ | |
-u consumer_key:consumer_secret \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"composite_components": [ | |
{ | |
"id": "123456789", | |
"delete": true | |
} | |
] | |
}' |
Orders ↑ Back to top
Line Item Properties ↑ Back to top
Attribute | Type | Context | Description |
---|---|---|---|
composite_parent |
string |
read |
Item ID of parent line item, applicable if the item is part of a composite. |
composite_children |
array |
read |
Item IDs of composited/child line items, applicable if the item is a composite container. |
composite_configuration |
string |
write |
Composite product configuration array. Must be defined when adding a composite-type line item to an order, to ensure components are added to the order as well. See Composite Configuration Properties. |
Composite Configuration Properties
Attribute | Type | Context | Description |
---|---|---|---|
component_id |
string |
write |
Component ID. |
product_id |
integer |
write |
Chosen product ID. |
quantity |
integer |
write |
Chosen product quantity. |
variation_id |
integer |
write |
Chosen variation ID, if applicable. |
attributes |
array |
write |
Chosen variation attributes, if applicable. See Variation Attribute Properties. |
args |
object |
write |
Additional arguments to pass into WC_Order::add_product , if applicable. |
Variation Attribute Properties
Attribute | Type | Context | Description |
---|---|---|---|
name |
string |
write |
Variation attribute name or slug. |
option |
string |
write |
Selected variation attribute option name. |
Working with Orders: Examples ↑ Back to top
Add Composite to Order
curl -X PUT https://example.com/wp-json/wc/v2/orders/199 \ | |
-u consumer_key:consumer_secret \ | |
-H "Content-Type: application/json" \ | |
-k \ | |
-d '{ | |
"line_items": [ | |
{ | |
"product_id": 101, | |
"quantity": 1, | |
"composite_configuration": [ | |
{ | |
"component_id": "1482917234", | |
"product_id": 114, | |
"quantity": 1, | |
"variation_id": 115, | |
"attributes": [ | |
{ | |
"name": "Attribute A", | |
"option": "Value A1" | |
}, | |
{ | |
"name": "Attribute B", | |
"option": "Value B1" | |
} | |
] | |
} | |
] | |
} | |
] | |
}' |
Questions & Support ↑ Back to top
Have a question? Please fill out this pre-sales form.
Already purchased and need assistance? Get in touch with us via the Help Desk!