1. Home
  2. Knowledge Base
  3. WooCommerce Product Options
  4. Developer Documentation

Actions and Filters

WooCommerce Product Options comes with some filters which allow you to customize the plugin's behavior.

The following actions and filters allow you to customize the main WooCommerce Product Options plugin. We have a separate article containing the actions and filters for the Live Preview add-on.

Please note that code snippets are aimed at developers. If you feel comfortable using them, our article on how to use code snippets can serve as a helpful guide. However, if you don't feel comfortable using them, then you should ask your developer. If you don't have one, then you can use our plugin customization service.

Actions

wc_product_options_after_cart_item_calculation

Calculates the product addon pricing in the cart.

Arguments

  • $cart (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Cart):

Example

add_action( 'wc_product_options_after_cart_item_calculation', 'my_wc_product_options_after_cart_item_calculation' );
function my_wc_product_options_after_cart_item_calculation( $cart ) {
	// your code here...
}

wc_product_options_after_cart_item_data_option

Display product options data in the cart and checkout.

Arguments

  • $item_data (array):
  • $cart_item (array):

Example

add_action( 'wc_product_options_after_cart_item_data_option', 'my_wc_product_options_after_cart_item_data_option', 10, 2 );
function my_wc_product_options_after_cart_item_data_option( $item_data, $cart_item ) {
	// your code here...
}

wc_product_options_after_cart_items_calculation

Calculates the product addon pricing in the cart.

Arguments

  • $cart (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Cart):

Example

add_action( 'wc_product_options_after_cart_items_calculation', 'my_wc_product_options_after_cart_items_calculation' );
function my_wc_product_options_after_cart_items_calculation( $cart ) {
	// your code here...
}

wc_product_options_after_field

Fires after the field is rendered.

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

Example

add_action( 'wc_product_options_after_field', 'my_wc_product_options_after_field', 10, 2 );
function my_wc_product_options_after_field( $field, $product ) {
	// your code here...
}

wc_product_options_after_field_wrap

Fires after the field wrap is rendered.

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

Example

add_action( 'wc_product_options_after_field_wrap', 'my_wc_product_options_after_field_wrap', 10, 2 );
function my_wc_product_options_after_field_wrap( $field, $product ) {
	// your code here...
}

wc_product_options_after_group_update

Create a group

Arguments

  • $request (\Barn2\Plugin\WC_Product_Options\Rest\Routes\WP_REST_Request):

Example

add_action( 'wc_product_options_after_group_update', 'my_wc_product_options_after_group_update' );
function my_wc_product_options_after_group_update( $request ) {
	// your code here...
}

wc_product_options_after_option_update

Update a option

Arguments

  • $request (\Barn2\Plugin\WC_Product_Options\Rest\Routes\WP_REST_Request):

Example

add_action( 'wc_product_options_after_option_update', 'my_wc_product_options_after_option_update' );
function my_wc_product_options_after_option_update( $request ) {
	// your code here...
}

wc_product_options_after_order_item_data

Add product options data to order item.

Arguments

  • $item (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order_Item_Product):
  • $cart_item_key (string):
  • $cart_item (array):
  • $order (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order):

Example

add_action( 'wc_product_options_after_order_item_data', 'my_wc_product_options_after_order_item_data', 10, 4 );
function my_wc_product_options_after_order_item_data( $item, $cart_item_key, $cart_item, $order ) {
	// your code here...
}

wc_product_options_after_order_item_data_option

Add product options data to order item.

Arguments

  • $item (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order_Item_Product):
  • $cart_item_key (string):
  • $cart_item (array):
  • $order (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order):

Example

add_action( 'wc_product_options_after_order_item_data_option', 'my_wc_product_options_after_order_item_data_option', 10, 4 );
function my_wc_product_options_after_order_item_data_option( $item, $cart_item_key, $cart_item, $order ) {
	// your code here...
}

wc_product_options_after_{$option_type}_field

Fires after the field is rendered.

The variable part of the hook name refers to the field type (i.e. `$field->option->type`)

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

wc_product_options_after_{$option_type}_field_wrap

Fires after the field wrap is rendered.

The variable part of the hook name refers to the field type (i.e. `$field->option->type`)

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

wc_product_options_before_cart_item_calculation

Calculates the product addon pricing in the cart.

Arguments

  • $cart (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Cart):

Example

add_action( 'wc_product_options_before_cart_item_calculation', 'my_wc_product_options_before_cart_item_calculation' );
function my_wc_product_options_before_cart_item_calculation( $cart ) {
	// your code here...
}

wc_product_options_before_cart_item_data_option

Display product options data in the cart and checkout.

Arguments

  • $item_data (array):
  • $cart_item (array):

Example

add_action( 'wc_product_options_before_cart_item_data_option', 'my_wc_product_options_before_cart_item_data_option', 10, 2 );
function my_wc_product_options_before_cart_item_data_option( $item_data, $cart_item ) {
	// your code here...
}

wc_product_options_before_cart_items_calculation

Calculates the product addon pricing in the cart.

Arguments

  • $cart (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Cart):

Example

add_action( 'wc_product_options_before_cart_items_calculation', 'my_wc_product_options_before_cart_items_calculation' );
function my_wc_product_options_before_cart_items_calculation( $cart ) {
	// your code here...
}

wc_product_options_before_field

Fires before the field is rendered.

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

Example

add_action( 'wc_product_options_before_field', 'my_wc_product_options_before_field', 10, 2 );
function my_wc_product_options_before_field( $field, $product ) {
	// your code here...
}

wc_product_options_before_field_wrap

Fires before the field wrap is rendered.

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

Example

add_action( 'wc_product_options_before_field_wrap', 'my_wc_product_options_before_field_wrap', 10, 2 );
function my_wc_product_options_before_field_wrap( $field, $product ) {
	// your code here...
}

wc_product_options_before_option_update

Update a option

Arguments

  • $request (\Barn2\Plugin\WC_Product_Options\Rest\Routes\WP_REST_Request):

Example

add_action( 'wc_product_options_before_option_update', 'my_wc_product_options_before_option_update' );
function my_wc_product_options_before_option_update( $request ) {
	// your code here...
}

wc_product_options_before_order_item_data

Add product options data to order item.

Arguments

  • $item (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order_Item_Product):
  • $cart_item_key (string):
  • $cart_item (array):
  • $order (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order):

Example

add_action( 'wc_product_options_before_order_item_data', 'my_wc_product_options_before_order_item_data', 10, 4 );
function my_wc_product_options_before_order_item_data( $item, $cart_item_key, $cart_item, $order ) {
	// your code here...
}

wc_product_options_before_order_item_data_option

Add product options data to order item.

Arguments

  • $item (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order_Item_Product):
  • $cart_item_key (string):
  • $cart_item (array):
  • $order (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order):

Example

add_action( 'wc_product_options_before_order_item_data_option', 'my_wc_product_options_before_order_item_data_option', 10, 4 );
function my_wc_product_options_before_order_item_data_option( $item, $cart_item_key, $cart_item, $order ) {
	// your code here...
}

wc_product_options_before_{$option_type}_field

Fires before the field is rendered.

The variable part of the hook name refers to the field type (i.e. `$field->option->type`)

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

wc_product_options_before_{$option_type}_field_wrap

Fires before the field wrap is rendered.

The variable part of the hook name refers to the field type (i.e. `$field->option->type`)

Arguments

  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.
  • $product (\WC_Product): The current product object.

Filters

wc_product_options_add_order_again_item_data

Whether to add product options data to cart item when ordering again.

Note that this filter is used for WC Subscriptions to determine whether to prevent recalculating the renewals.

Arguments

  • $enabled (bool):
  • $item (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order_Item_Product):
  • $order (\Barn2\Plugin\WC_Product_Options\Handlers\WC_Order):

wc_product_options_allow_negative_prices

Filters the condition determing whether negative prices are allowed.

Arguments

  • $allow_negative_prices (bool): Whether negative prices are allowed.
  • $product (\WC_Product): The product which is being calculated.
  • $cart_item (array): The cart item.

Example

add_filter( 'wc_product_options_allow_negative_prices', 'my_wc_product_options_allow_negative_prices', 10, 3 );
function my_wc_product_options_allow_negative_prices( $allow_negative_prices, $product, $cart_item ) {
	// your code to alter $allow_negative_prices here...

	return $allow_negative_prices;
}

wc_product_options_allowed_product_types

Filters the allowed product types.

Arguments

  • $product_types (array): The allowed product types.

Example

add_filter( 'wc_product_options_allowed_product_types', 'my_wc_product_options_allowed_product_types' );
function my_wc_product_options_allowed_product_types( $product_types ) {
	// your code to alter $product_types here...

	return $product_types;
}

wc_product_options_cart_price

Filter the price of an option choice in the cart.

Arguments

  • $option_price (float):
  • $product (\Barn2\Plugin\WC_Product_Options\Util\WC_Product):
  • $price_data (array):

Example

add_filter( 'wc_product_options_cart_price', 'my_wc_product_options_cart_price', 10, 3 );
function my_wc_product_options_cart_price( $option_price, $product, $price_data ) {
	// your code to alter $option_price here...

	return $option_price;
}

wc_product_options_choice_label_price

Filter the price of an option choice.

Arguments

  • $choice_price (float):
  • $product (\Barn2\Plugin\WC_Product_Options\Util\WC_Product):
  • $choice_price (float):

Example

add_filter( 'wc_product_options_choice_label_price', 'my_wc_product_options_choice_label_price', 10, 3 );
function my_wc_product_options_choice_label_price( $choice_price, $product, $choice_price ) {
	// your code to alter $choice_price here...

	return $choice_price;
}

wc_product_options_create_upload_thumbnails

Example

add_filter( 'wc_product_options_create_upload_thumbnails', 'my_wc_product_options_create_upload_thumbnails' );
function my_wc_product_options_create_upload_thumbnails() {
	// your code here...
}

wc_product_options_dropzone_preview_template

Filter the dropzone preview template.

Arguments

  • $template (string): The template.
  • $id (string): The field ID.
  • $this (self): The field.

Example

add_filter( 'wc_product_options_dropzone_preview_template', 'my_wc_product_options_dropzone_preview_template', 10, 3 );
function my_wc_product_options_dropzone_preview_template( $template, $id, $this ) {
	// your code to alter $template here...

	return $template;
}

wc_product_options_enable_price_calculation

Filters whether to allow product option price calculation on a product.

Arguments

  • $enable (bool): Whether to allow product option price calculation on a product.
  • $product (\WC_Product): The product which is being calculated.
  • $cart_item (array|null): The cart item if this is calculated in the cart.

Example

add_filter( 'wc_product_options_enable_price_calculation', 'my_wc_product_options_enable_price_calculation', 10, 3 );
function my_wc_product_options_enable_price_calculation( $enable, $product, $cart_item ) {
	// your code to alter $enable here...

	return $enable;
}

wc_product_options_external_conditions

Filters the parameters for the script of the admin page.

Arguments

  • $params (array): The array of parameters.

Example

add_filter( 'wc_product_options_external_conditions', 'my_wc_product_options_external_conditions' );
function my_wc_product_options_external_conditions( $params ) {
	// your code to alter $params here...

	return $params;
}

wc_product_options_field_classes

Filters the field classes.

Arguments

  • $fields (array): The field classes.

Example

add_filter( 'wc_product_options_field_classes', 'my_wc_product_options_field_classes' );
function my_wc_product_options_field_classes( $fields ) {
	// your code to alter $fields here...

	return $fields;
}

wc_product_options_field_css_class

Filters the CSS classes for the field.

Arguments

  • $class_string (string):
  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field):

Example

add_filter( 'wc_product_options_field_css_class', 'my_wc_product_options_field_css_class', 10, 2 );
function my_wc_product_options_field_css_class( $class_string, $field ) {
	// your code to alter $class_string here...

	return $class_string;
}

wc_product_options_field_has_display_prerequisites

Filters whether the field should be displayed.

Arguments

  • $display (bool): True if the field should be displayed, false otherwise.
  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.

Example

add_filter( 'wc_product_options_field_has_display_prerequisites', 'my_wc_product_options_field_has_display_prerequisites', 10, 2 );
function my_wc_product_options_field_has_display_prerequisites( $display, $field ) {
	// your code to alter $display here...

	return $display;
}

wc_product_options_file_expiry_time

Filter the file expiry time.

Arguments

  • $file_expiry (int): The time in seconds after which a file is considered expired.

Example

add_filter( 'wc_product_options_file_expiry_time', 'my_wc_product_options_file_expiry_time' );
function my_wc_product_options_file_expiry_time( $file_expiry ) {
	// your code to alter $file_expiry here...

	return $file_expiry;
}

wc_product_options_formula_custom_functions

Example

add_filter( 'wc_product_options_formula_custom_functions', 'my_wc_product_options_formula_custom_functions' );
function my_wc_product_options_formula_custom_functions() {
	// your code here...
}

wc_product_options_formula_custom_js_functions

Example

add_filter( 'wc_product_options_formula_custom_js_functions', 'my_wc_product_options_formula_custom_js_functions' );
function my_wc_product_options_formula_custom_js_functions() {
	// your code here...
}

wc_product_options_get_frontend_string

Get the output string for the field.

This method runs a filter to allow for further string customization, including internationalization.

Arguments

  • $string_value (string):
  • $args (array):

wc_product_options_get_item_data

Filter the item data displayed in the cart and checkout.

Arguments

  • $item_data (array): The array of metadata attached to each cart item
  • $cart_item (array): The cart item

Example

add_filter( 'wc_product_options_get_item_data', 'my_wc_product_options_get_item_data', 10, 2 );
function my_wc_product_options_get_item_data( $item_data, $cart_item ) {
	// your code to alter $item_data here...

	return $item_data;
}

wc_product_options_get_output_string

Retrieves the HTML for the supplied groups.

Arguments

  • $groups (array):
  • $product (\Barn2\Plugin\WC_Product_Options\Util\WC_Product):

Example

add_filter( 'wc_product_options_get_output_string', 'my_wc_product_options_get_output_string', 10, 2 );
function my_wc_product_options_get_output_string( $groups, $product ) {
	// your code to alter $groups here...

	return $groups;
}

wc_product_options_get_setting

Filters the value of a specific field setting.

Arguments

  • $value (string|array): The value of the setting being filtered.
  • $setting_name (string): The key of the setting being filtered.
  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The field object.
  • $product (\WC_Product): The product object.

Example

add_filter( 'wc_product_options_get_setting', 'my_wc_product_options_get_setting', 10, 4 );
function my_wc_product_options_get_setting( $value, $setting_name, $field, $product ) {
	// your code to alter $value here...

	return $value;
}

wc_product_options_get_settings

Filters the array with the field settings.

Arguments

  • $settings (array): The array with the field settings.
  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The field object.
  • $product (\WC_Product): The product object.

Example

add_filter( 'wc_product_options_get_settings', 'my_wc_product_options_get_settings', 10, 3 );
function my_wc_product_options_get_settings( $settings, $field, $product ) {
	// your code to alter $settings here...

	return $settings;
}

wc_product_options_get_{$setting_name}_setting

Filters the value of a specific field setting.

The variable portion of the filter name refers to the setting name.

Arguments

  • $value (string|array): The value of the setting being filtered.
  • $field (\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The field object.
  • $product (\WC_Product): The product object.

wc_product_options_group_categories

Filter the list of term IDs so that other plugins can add or remove terms.

Arguments

  • $term_ids (array): The list of all term IDs.

Example

add_filter( 'wc_product_options_group_categories', 'my_wc_product_options_group_categories' );
function my_wc_product_options_group_categories( $term_ids ) {
	// your code to alter $term_ids here...

	return $term_ids;
}

wc_product_options_group_products

Filter the list of product IDs so that other plugins can add or remove products.

Arguments

  • $product_ids (array): The list of all product IDs.

Example

add_filter( 'wc_product_options_group_products', 'my_wc_product_options_group_products' );
function my_wc_product_options_group_products( $product_ids ) {
	// your code to alter $product_ids here...

	return $product_ids;
}

wc_product_options_handle_add_to_cart_validation

Filters whether to allow product option price calculation on a product.

Arguments

  • $enable (bool): Whether to handle validation on the product
  • $product_id (int): The product ID which is being validated.
  • $quantity (int): The quantity of the product being validated.
  • $variation_id (int|null): The variation ID if this is a variation.
  • $variation (\Barn2\Plugin\WC_Product_Options\Util\WC_Product_Variation): The variation if this is a variation.

Example

add_filter( 'wc_product_options_handle_add_to_cart_validation', 'my_wc_product_options_handle_add_to_cart_validation', 10, 5 );
function my_wc_product_options_handle_add_to_cart_validation( $enable, $product_id, $quantity, $variation_id, $variation ) {
	// your code to alter $enable here...

	return $enable;
}

wc_product_options_is_update_main_image_enabled

Filter whether the option has the "Update main image" setting enabled.

Thanks to this filter, the "Update main image" can be forced to be enabled/disabled site-wide or on specific products without any need to manually change any of the existing options.

Arguments

  • $option (\Barn2\Plugin\WC_Product_Options\Fields\Image_Buttons): The current option object.
  • $product (\Barn2\Plugin\WC_Product_Options\Fields\WC_Product): The current product object.

Example

add_filter( 'wc_product_options_is_update_main_image_enabled', 'my_wc_product_options_is_update_main_image_enabled', 10, 2 );
function wc_product_options_is_update_main_image_enabled( $is_enabled, $option, $product ) {
    if ( $product->get_id() === 123 ) {
	       return true;
    }

    return $is_enabled;
}

wc_product_options_live_preview_default_customize_button_text

Text input field class.

Example

add_filter( 'wc_product_options_live_preview_default_customize_button_text', 'my_wc_product_options_live_preview_default_customize_button_text' );
function my_wc_product_options_live_preview_default_customize_button_text() {
	// your code here...
}

wc_product_options_minus_sign

Filter the character used as a minus sign.

Arguments

  • $sign (string): The minus sign.
  • $price (float): The price.
  • $currency_pos (string): The currency position.

Example

add_filter( 'wc_product_options_minus_sign', 'my_wc_product_options_minus_sign', 10, 3 );
function my_wc_product_options_minus_sign( $sign, $price, $currency_pos ) {
	// your code to alter $sign here...

	return $sign;
}

wc_product_options_multiple_cart_item_data_seperator

Filter the formatted item data string.

Used in the cart, checkout, orders, and emails. Default ' | ' separator.

Arguments

  • $seperator (string):

wc_product_options_plus_sign

Filter the character used as a plus sign.

Arguments

  • $sign (string): The plus sign.
  • $price (float): The price.
  • $currency_pos (string): The currency position.

Example

add_filter( 'wc_product_options_plus_sign', 'my_wc_product_options_plus_sign', 10, 3 );
function my_wc_product_options_plus_sign( $sign, $price, $currency_pos ) {
	// your code to alter $sign here...

	return $sign;
}

wc_product_options_product_price_container

Filters the product price to display in the totals container.

Arguments

  • $price (float): The product price.
  • $product (\Barn2\Plugin\WC_Product_Options\Util\WC_Product): The product object.

Example

add_filter( 'wc_product_options_product_price_container', 'my_wc_product_options_product_price_container', 10, 2 );
function my_wc_product_options_product_price_container( $price, $product ) {
	// your code to alter $price here...

	return $price;
}

wc_product_options_setting_tabs

Render the Settings page.

Example

add_filter( 'wc_product_options_setting_tabs', 'my_wc_product_options_setting_tabs' );
function my_wc_product_options_setting_tabs() {
	// your code here...
}

wc_product_options_settings_app_params

Filters the parameters for the script of the admin page.

Arguments

  • $params (array): The array of parameters.

Example

add_filter( 'wc_product_options_settings_app_params', 'my_wc_product_options_settings_app_params' );
function my_wc_product_options_settings_app_params( $params ) {
	// your code to alter $params here...

	return $params;
}

wc_product_options_uploads_thumbnail_quality

Filter the quality for the thumbnail.

Arguments

  • $quality (int): The quality of the thumbnail.
  • $file (array): The file data.

Example

add_filter( 'wc_product_options_uploads_thumbnail_quality', 'my_wc_product_options_uploads_thumbnail_quality', 10, 2 );
function my_wc_product_options_uploads_thumbnail_quality( $quality, $file ) {
	// your code to alter $quality here...

	return $quality;
}

wc_product_options_uploads_thumbnail_size

Filter the thumbnail dimensions.

Specify an array the width and height of the thumbnail in pixels. If either width or height is null, the thumbnail will be resized proportionally. Returning null will effectively prevent the thumbnail from being generated.

Arguments

  • $size (array): The size of the thumbnail as an array of width and height.
  • $file (array): The file data.

wc_product_options_uploads_use_year_month

Filter whether to use year/month folders for uploaded files.

Arguments

  • $use_year_month (bool): Whether to use year/month folders for uploaded files. Default false.

Example

add_filter( 'wc_product_options_uploads_use_year_month', '__return_true' );

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.