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

Actions and Filters

Actions

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_{$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_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_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_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

Filters whether to create thumbnails for uploaded images.

Arguments

  • $create_thumbnails (bool): Whether to create thumbnails for uploaded images. Default false.

Example

add_filter( 'wc_product_options_create_upload_thumbnails', '__return_true' );

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_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_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_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_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_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_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;
}

Related Articles

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