Filters Reference

This page is written for WooCommerce developers looking to extend or customize WooCommerce Composite Products. It requires an advanced understanding of PHP and WordPress development.

Summary

↑ Back to top

This guide documents the most useful filter hooks available in Composite Products. It is not an exhaustive reference of all available filters and does not include tutorials on how to achieve certain tasks.

We recommend reading Data Structures and Storage and keeping the Functions Reference handy. Take time to familiarize yourself with the plugin architecture and the objects relevant to the hook you want to use.

Product Filters Summary

↑ Back to top
Name Description
woocommerce_min_composite_price
woocommerce_max_composite_price

Used to manually define min/max raw (regular) prices of a composite product when price calculations are overridden, typically when the Hide Price option is ticked.
woocommerce_min_composite_price_index
woocommerce_max_composite_price_index

Used to manually define product configurations used to render the min/max (regular) prices of a composite product when price calculations are overridden, typically when the Hide Price option is ticked.
woocommerce_composite_scenario_meta Filters raw scenario data stored in the _bto_scenario_data meta field. Use it to create scenarios programmatically.
woocommerce_composite_cart_permalink_args Modifies the arguments added to the permalink of a composite product when editing its configuration from the cart.
woocommerce_composited_product_discount_from_regular Modifies the reference price (regular or sale) used for calculating component discounts.

Template Filters Summary

↑ Back to top
Name Description
woocommerce_composite_component_toggled Used for enabling/disabling toggle-box component views when using the Stacked or Progressive layout.
woocommerce_composite_summary_widget_display Used to conditionally show/hide the Composite Products Summary widget.
woocommerce_composite_sequential_comp_progress Used to force a sequential configuration process when using the Componentized layout.
woocommerce_composite_component_classes Modifies the class names attached to component container div elements.
woocommerce_composited_product_quantity Changes the default quantity of the chosen product.
woocommerce_composite_component_loop_columns Changes the number of product columns displayed when the Thumbnails style is selected.
woocommerce_composite_component_summary_max_columns Changes the max number of columns displayed in the Summary section when the Stepped or Componentized layout is active.
woocommerce_component_options_pagination_range Changes the number of pagination elements displayed before/after the current Component Options page when the Thumbnails style is enabled.
woocommerce_composite_front_end_params Modifies the parameters passed to the single-product add-to-cart script.
woocommerce_composite_summary_vertical_style Forces a non-responsive but mobile-friendly, vertical Summary section layout.
woocommerce_composite_component_option_prices_hide Modifies the visibility of Component Option prices in the Dropdown, Thumbnails and Radio Buttons templates when Priced Individually is ticked.
woocommerce_composited_product_price_string Filters the html price string of products listed in component drop-down menus when the Dropdown style is active.
woocommerce_composited_product_price_suffix Filters the html price string suffix of products listed in component drop-down menus when the Dropdown style is active.
woocommerce_component_options_per_page Modifies the number of Component Options loaded per page when the Thumbnails style is active.
woocommerce_component_options_paginate_results Controls whether Component Options will be paginated (default) or appended using a Load More button when the Thumbnails style is active.
woocommerce_component_options_hide_incompatible Controls whether disabled products and variation attribute values will be greyed-out or hidden when using the Hide Component Options Action.
woocommerce_composite_component_orderby Modifies the available Component Options sorting functions.
woocommerce_composite_component_default_orderby Modifies the Component Options sorting function used by default.
woocommerce_composite_component_filters Modifies the available Component Option filtering options.
woocommerce_composite_component_lazy_load Controls whether Component Options will be lazy loaded.

Cart Filters Summary

↑ Back to top
Name Description
woocommerce_composite_component_add_to_cart_validation Modifies the validation result of a component configuration array.
woocommerce_composited_product_has_bundled_weight Allows you to add the weight of a child item that is not Shipped Individually to the base weight of its physical parent.
woocommerce_composited_cart_item Μodifies the cart item data of composite children (re-applied on session load).
woocommerce_composite_container_cart_item Μodifies the cart item data of composite containers (re-applied on session load).
woocommerce_composite_component_cart_item_identifier Used to add custom fields to the configuration data of a composite product when it is added to the cart. Commonly used when custom configuration input fields have been added to composited products – e.g. Product Add-Ons fields.
woocommerce_composited_cart_item_data Provides an opportunity to modify child cart item data by copying data already stored in the parent cart item. Commonly used to copy data previously added using this filter.
woocommerce_add_composited_cart_item_subtotals Modifies the way composite subtotals appear in the cart.

Order Filters Summary

↑ Back to top
Name Description
woocommerce_add_composited_order_item_subtotals Modifies the way composite subtotals appear when displaying order details.
woocommerce_composite_container_order_item_sku Alters the SKU of a composite product object modified using the get_product_from_item method, based on a list of child products and quantities assembled in the composite.

Admin Filters Summary

↑ Back to top
Name Description
woocommerce_composite_process_component_data Modifies component settings fields. Useful for intercepting and processing custom fields.
woocommerce_composite_process_scenario_data Modifies scenario settings fields. Useful for intercepting and processing custom fields.
woocommerce_composite_component_admin_html_tabs Used to create extra tabs to display custom component admin options, in addition to the default Basic Settings and Advanced Settings tabs.

Product Filters

↑ Back to top

woocommerce_min_composite_price

woocommerce_max_composite_price

Description

Group of filters that can be used to define the min/max raw prices of a composite product when price calculations are overridden, typically when the Hide Price option is ticked. Intended for large-scale applications which may require ticking the Hide Price option for performance reasons only.

Arguments

string|integer $price – Raw min/max (regular) price.
WC_Product_Composite $composite – Composite product object.


woocommerce_min_composite_price_index

woocommerce_max_composite_price_index

Description

When price calculations are overridden, these filters define the product combinations to use when getting composite product prices. Typically used when the Hide Price option is ticked. Intended for large-scale applications which may require ticking the Hide Price option for performance reasons.

Arguments

array $index – Array of product IDs, indexed by component ID.
WC_Product_Composite $composite – Composite product object.


woocommerce_composite_scenario_meta

Description

Allows you to filter the raw scenario metadata used for building scenario data arrays. Raw data is organized in the _bto_scenario_data meta field.

If you want to create scenarios programmatically, for example by building your own dynamic queries to organize products/variations in scenarios, consider hooking into this filter.

Note that the “any” Condition modifier corresponds to an ID of 0 in the metadata array, and the “No Selection” option to an ID of -1.

Arguments

array $meta – Array of raw scenario data.
WC_Product_Composite $composite – Composite product object.


Description

Use this filter to modify the arguments added to the permalink of a composite product when editing its configuration from the cart.

Arguments

array $args – Parameter name/values to add to the permalink.
array|false $cart_item – Container cart item associated with the composite product when WC_Product_Composite::is_editable_in_cart is called in cart context.
WC_Product_Composite $composite – Composite product object.


woocommerce_composited_product_discount_from_regular

Description

Use this filter to change the reference price used for calculating component discounts (regular or sale).

Arguments

boolean $calc_discounts_from_regular – Indicates whether to calculate discounts using regular prices as reference. Defaults to false.
integer $component_id – Component ID.
integer $composite_id – Composite product ID.

Example

In this snippet, the filter is used to allow Component Option discounts over regular prices.

Template Filters

↑ Back to top

woocommerce_composite_component_toggled

Description

Used for enabling/disabling toggle-box component views when using the Stacked or Progressive layout.

Arguments

boolean $toggled – When set to true, the associated Component is wrapped into a toggle-box that can be opened/closed by clicking on the Component title.
string $component_id – Component ID
Id of the associated Component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_summary_widget_display

Description

Used to conditionally show/hide the Composite Products Summary widget.

Arguments

boolean $show – Whether to show the widget.
string $layout_style – Base layout of the Composite.
string $layout_style_variation – Layout variation of the Composite.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_sequential_comp_progress

Description

Used to force a sequential configuration process when using the Componentized layout.

Arguments

string $force – Whether to show the widget. Values yes|no.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_classes

Description

Modifies the class names attached to component container div elements.

The included classes control various aspects of the JS app UI/UX. Removing classes may result in loss of functionality: Do not modify these classes for styling purposes. The classes listed in the following table can be added/removed to enable/modify functionality that is otherwise inaccessible from the admin UI:

Class Name Description
toggled Enables the toggle-box UI for the associated Component. In effect when using the Stacked or Progressive layout.
autotransition When using the Progressive, Paged, or Componentized layout, this class can be used to automatically transition to the next step as soon as a valid selection is made.
autoselect_attributes Automatically selects the remaining variation attribute when all the rest are excluded by Scenarios.

Arguments

array $classes – Array containing class names to be imploded.
string $component_id – ID of the associated Component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composited_product_quantity

Description

Changes the default quantity of the chosen product.

Arguments

int $qty_value – Default value.
int $min_qty – Min component quantity.
int $max_qty – Max component quantity.
WC_Product $product – The chosen product object.
string $component_id – ID of the associated Component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_loop_columns

Description

Changes the number of columns displayed when the Thumbnails style is active and the form.composite_form width is higher than the full_width_threshold value defined in woocommerce_composite_front_end_params.

Arguments

int $columns – Default value, by default one less than the WooCommerce product loop column count.
string $component_id – ID of the associated Component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_summary_max_columns

Description

Changes the max number of Component columns displayed in the Summary section when the width of form.composite_form is higher than the full_width_threshold value defined in woocommerce_composite_front_end_params.

Defaults to 6.

Arguments

int $columns – Default value.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_component_options_pagination_range

Description

Changes the number of pagination elements displayed before/after the current Component Options page when the Thumbnails style is enabled.

Arguments

int $range – Number of pagination elements to display before/after the current page.
string $component_id – ID of the associated Component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_front_end_params

Description

Use this filter to modify the parameters passed into the add-to-cart-composite.js script.

Parameter Description
small_width_threshold When the form.composite_form element width drops below this pixel threshold, the front-end layout folds according to the .small_width responsive CSS rules in assets/css/wc-composite-single.css.

The .small_width CSS rules re-arrange the Thumbnails loop and the Summary template elements in a vertically stacked layout optimized for mobile devices.

Type: integer
Default: 450

full_width_threshold When the form.composite_form width increases above this pixel threshold, the layout of the Thumbnails loop and Summary template elements expands according to the .full_width responsive CSS rules in assets/css/wc-composite-single.css.

When full_width_threshold is exceeded, the number of Component Option columns is controlled by the woocommerce_composite_component_loop_columns filter. Similarly, the max number of Component columns in the Summary section is controlled by the woocommerce_composite_component_summary_max_columns filter.

Type: integer
Default: 450

i18n_* Localized notices and link/button strings rendered by the script. Refer to includes/wc-cp-display.php for details.
currency_* Currency and price format options. Refer to includes/wc-cp-display.php for details.
show_quantity_buttons Set this field to yes when using an external plugin with WooCommerce 2.3+ to add +/- quantity buttons. Setting this field to ‘yes’ will output the +/- button markup found in WooCommerce 2.2.

Type: string
Values: yes|no
Default: no

price_display_suffix Suffix to append to composite totals calculated by the JS app – a copy of the woocommerce_price_display_suffix option.

Type: string

Arguments

array $params – Array of parameters.


woocommerce_composite_summary_vertical_style

Description

Forces a non-responsive but mobile-friendly, vertical arrangement of Summary section elements.

Arguments

boolean $force_vertical – Whether to force a vertical arrangement of Summary section elements.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_option_prices_hide

Description

Modifies the visibility of Component Option prices in the Dropdown, Thumbnails and Radio Buttons templates when Priced Individually is ticked.

Arguments

boolean $hide – Whether to hide prices. Defaults to false.
WC_CP_Component $component – Component object.


woocommerce_composited_product_price_string

Description

Filters the html price strings listed in drop-down menus when the Dropdown style is active and the Priced Individually option is ticked.

Arguments

string $price_string – Unmodified output.
integer $product_id – ID of the product whose price is displayed.
string $component_id – ID of the associated Component.
WC_CP_Product $component_option – Component option wrapper object.


woocommerce_composited_product_price_suffix

Description

Filters the html price string suffix of products listed in drop-down menus when the Dropdown style is active and the Priced Individually option is ticked.

Arguments

string $pct_off – Unmodified output.
string $component_id – ID of the associated Component.
integer $product_id – ID of the product whose price is displayed.
float $price – The (minimum) price of the product.
float $regular_price – The (minimum) regular price of the product.
boolean $is_nyp – True if the product is a Name-Your-Price product.
boolean $is_range – True if the product price is variable.
WC_CP_Product $component_option – Component option wrapper object.


woocommerce_component_options_per_page

Description

Modifies the number of Component Options loaded per page when the Thumbnails style is active.

Arguments

integer $options_per_page – Defaults to [component options loop columns] x 2. Note that the number of component options columns is controlled by woocommerce_composite_component_loop_columns.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_component_options_paginate_results

Description

Controls whether Component Options will be paginated (default) or appended using a Load More button when the Thumbnails style is active.

Arguments

boolean $paginate – Defaults to true.
string $component_id – ID of the associated Component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_component_options_hide_incompatible

Description

Controls whether incompatible products and variation attribute values will be greyed-out or hidden when Scenarios are used to Hide Component Options.

Arguments

boolean $hide – Defaults to true.
string $component_id – ID of the associated component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_orderby

Description

Modifies the available Component Options sorting functions. By default, the extension includes the following core sorting functions:

View on Github

Adding a new sorting function with this hook will create an additional front-end drop-down option in the templates/single-product/component-options-orderby.php template. Note that after adding a custom sorting option, you will also need to implement it by hooking into the WC_CP_Query filters API.

Arguments

string $component_id – ID of the associated component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_default_orderby

Description

Use this filter to change the default sorting option. Defaults to default, which sorts Component Options by:

  • the order they have been entered, if Component Options have been entered by ID.
  • date (post_date), if Component Options have been entered by category.

For a list of sorting functions, see woocommerce_composite_component_orderby.

Arguments

string $sort_id – ID of the default sort function.
string $component_id – ID of the associated component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_filters

Description

Modifies the available Component Option filtering options.

Arguments

array $active_filters – Array of filter options, each having the following structure:

Field Description
filter_type Type-identifier of the filtering group, used to identify and implement the query associated with this filter type. For instance, all attribute filters are of the attribute_filter type.
filter_id ID used to identify different filtering groups of the same type. For instance, each attribute filter is identified by the attribute taxonomy slug.
filter_name A title used for identifying this filtering group in the front-end, e.g. Size.
filter_options Array of the filtering options available under this group. Keys are used to identify options from a querying perspective, while values simply hold the corresponding descriptions in the front-end. For instance, the options of a Size attribute are the term IDs/names associated with Size. A possible array could be: array( 43 => 'Small', 32 => 'Medium', 44 => 'Large' ).

string $component_id – ID of the associated component.
WC_Product_Composite $composite_product – Composite product object.


woocommerce_composite_component_lazy_load

Description

Controls whether Component Options will be lazy-loaded. By default, product options in Componentized/Stepped/Progressive components are lazy-loaded unless the total number of options in the entire Composite is below 24. The first component of a Stepped/Progressive Composite is never lazy loaded. Additionally, product options in Stacked Composites are lazy loaded when using the Dropdown/Radio style and the number of Component Options is higher than 24.

Arguments

boolean $lazy_load – Whether to lazy-load the product options available in this component.
WC_CP_Component $component – The component object.

Cart Filters

↑ Back to top

woocommerce_composite_component_add_to_cart_validation

Description

Use this filter to further validate a component configuration before the composite product gets added to the cart.

Arguments

boolean $passes_validation – Validation result.
integer $composite_id – ID of composite product being validated.
integer $component_id – ID of component being validated.
integer $product_id – ID of the selected product.
integer $quantity – Selected product quantity.
array $cart_item_data – Cart item data array.
WC_Product_Composite $composite – Composite product object.
array $component_configuration – Component configuration array.


woocommerce_composited_product_has_bundled_weight

Description

When creating an Assembled Composite, you can use the Assembled Weight option to control how to calculate its weight. If the assembly has a static weight, you can choose the Ignore option, while if you prefer to calculate its weight dynamically, you can choose the Preserve option. When Preserve is selected, the weight of the assembly is calculated by adding:

  • the specified container Weight; and
  • the weight of all assembled Components.

With this filter, it is possible to control whether to add or ignore individual Component weights programmatically.

Arguments

boolean $add_weight_to_container – Indicates whether the weight of this child product (Component) should be appended to the weight of its parent. Defaults to false.
WC_Product $product – Child product object.
integer $component_id – ID of the associated component.
WC_Product_Composite $composite – Composite product object.


woocommerce_composited_cart_item

Description

Use this filter to modify the cart item data of composite child products (re-applied on session load).

Arguments

array $cart_item – Cart item data of child product.
WC_Product_Composite $composite – Composite product object.


woocommerce_composite_container_cart_item

Description

Use this filter to modify the cart item data of composite containers (re-applied on session load).

Arguments

array $cart_item – Cart item data of parent composite product.
WC_Product_Composite $composite – Composite product object.


woocommerce_composite_component_cart_item_identifier

Description

Use this filter to add custom fields to the configuration data of a composite product when it is added to the cart. Commonly used custom configuration input fields have been added to child products.

Arguments

array $component_configuration – Component configuration array.
integer $component_id – Component ID.
integer $composite_id – Composite product ID.

Examples

The use of this filter is demonstrated in the WC_CP_Addons_Compatibility class, which contains compatibility code for the Product Add-Ons extension. The filter is used to read posted data associated with child Product Add-Ons fields before adding the composite to the cart, in order to pass them to the hashing function used to generate the cart ID of the composite.


woocommerce_composited_cart_item_data

Description

Provides an opportunity to modify child cart item data by copying data that is already stored in the parent cart item. Commonly used to copy data added using the woocommerce_composite_component_cart_item_identifier filter.

Arguments

array $child_item_cart_data – Custom fields to add to the cart item data of a composite child product when it gets added to the cart.
integer $cart_item_data – Cart item data of the parent (just added to the cart).

Examples

The use of this filter is demonstrated in the WC_CP_Addons_Compatibility class, which contains compatibility code for the Product Add-Ons extension. The filter is used to copy child Product Add-Ons fields from the parent cart item.


woocommerce_add_composited_cart_item_subtotals

Description

By default, the cart item subtotal of a composite container item is calculated as the sum of the base composite price subtotal + the subtotals of any child items that are priced individually, while the subtotals of individually-priced items are displayed with a ‘Subtotal:’ prefix. The filter can be used to prevent this.

Arguments

boolean $add_subtotals – Indicates whether to modify the way subtotals appear. Defaults to true.
array $container_item_data – Container/parent cart item.
array $container_item_key – Container/parent cart item key.

Example

This snippet demonstrates how to prevent the extension from modifying item subtotals in the cart.

Order Filters

↑ Back to top

woocommerce_add_composited_order_item_subtotals

Description

By default, the cart item subtotal of a composite container item is calculated as the sum of the base composite price subtotal + the subtotals of any child items that are priced individually, while the subtotals of individually-priced items are displayed with a ‘Subtotal:’ prefix. The filter can be used to prevent this.

Arguments

boolean $add_subtotals – Indicates whether to modify the way subtotals appear. Defaults to true.
array $container_item_data – Container/parent order item.
WC_Order $order – Order object.

Example

This snippet demonstrates how to prevent the extension from modifying item subtotals in order details.


woocommerce_composite_container_order_item_sku

Description

Use this filter to alter the SKU of a composite object modified using the get_product_from_item method, based on a list of assembled child products and quantities (in this context “assembled” refers to items that are not Shipped Individually).

Arguments

string $sku – The SKU.
WC_Product $product – The Composite product object.
WC_Order_Item_Product $container_item – Container/parent order item.
array $assembled_items – Bundled order items physically assembled in the Composite for shipping.
WC_Order $order – Order object.

Admin Filters

↑ Back to top

woocommerce_composite_process_component_data

Description

Use this filter to intercept and process custom component fields.

Arguments

array $processed_data – Array of parameters to be used for adding/updating a specific component.
array $posted_data – Array of posted data associated with a specific component.
integer|'' $component_id – ID of the component when updating, or empty when creating it for the first time.
integer $composite_id – ID of the composite.


woocommerce_composite_process_scenario_data

Description

Use this filter to intercept and process custom scenario fields.

Arguments

array $processed_data – Array of scenario parameters to be added/updated.
array $posted_data – Array of posted data.
integer|'' $scenario_id – ID of the component when updating, or empty when creating it for the first time.
array $composite_data – Array of processed component data.
integer $composite_id – ID of the composite.


woocommerce_composite_component_admin_html_tabs

Description

Use this filer to create extra tabs to display custom admin options for components, in addition to the default Basic Settings and Advanced Settings tabs.

Arguments

array $tabs – Array tab sections to display.

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!

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.