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
Update 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_container
Retrieves the HTML for the supplied groups.
Arguments
$groups(array):$product(\WC_Product):
Example
add_action( 'wc_product_options_after_option_container', 'my_wc_product_options_after_option_container', 10, 2 );
function my_wc_product_options_after_option_container( $groups, $product ) {
// your code here...
}
wc_product_options_after_option_update
Update a group
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(\WC_Order_Item_Product):$cart_item_key(string):$cart_item(array):$order(\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(\WC_Order_Item_Product):$cart_item_key(string):$cart_item(array):$order(\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_{$field_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.
Example
add_action( 'wc_product_options_after_{$field_type}_field', 'my_wc_product_options_after_field_type_field', 10, 2 );
function my_wc_product_options_after_field_type_field( $field, $product ) {
// your code here...
}
wc_product_options_after_{$field_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.
Example
add_action( 'wc_product_options_after_{$field_type}_field_wrap', 'my_wc_product_options_after_field_type_field_wrap', 10, 2 );
function my_wc_product_options_after_field_type_field_wrap( $field, $product ) {
// your code here...
}
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_checkout_link
Adds a checkout link above the cart for shop managers to share the cart with customers.
This feature requires WooCommerce Store API to be active. The link includes a session token that allows customers to access the cart without logging in. Only shop managers can see this link.
Example
add_action( 'wc_product_options_before_checkout_link', 'my_wc_product_options_before_checkout_link' );
function my_wc_product_options_before_checkout_link() {
// 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_container
Retrieves the HTML for the supplied groups.
Arguments
$groups(array):$product(\WC_Product):
Example
add_action( 'wc_product_options_before_option_container', 'my_wc_product_options_before_option_container', 10, 2 );
function my_wc_product_options_before_option_container( $groups, $product ) {
// your code here...
}
wc_product_options_before_option_update
Update a group
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(\WC_Order_Item_Product):$cart_item_key(string):$cart_item(array):$order(\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(\WC_Order_Item_Product):$cart_item_key(string):$cart_item(array):$order(\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_{$field_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.
Example
add_action( 'wc_product_options_before_{$field_type}_field', 'my_wc_product_options_before_field_type_field', 10, 2 );
function my_wc_product_options_before_field_type_field( $field, $product ) {
// your code here...
}
wc_product_options_before_{$field_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.
Example
add_action( 'wc_product_options_before_{$field_type}_field_wrap', 'my_wc_product_options_before_field_type_field_wrap', 10, 2 );
function my_wc_product_options_before_field_type_field_wrap( $field, $product ) {
// your code here...
}
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(\WC_Order_Item_Product):$order(\WC_Order):
Example
add_filter( 'wc_product_options_add_order_again_item_data', 'my_wc_product_options_add_order_again_item_data', 10, 3 );
function my_wc_product_options_add_order_again_item_data( $enabled, $item, $order ) {
// your code to alter $enabled here...
return $enabled;
}
wc_product_options_addons_use_cart_quantity
Filters whether to use the product quantity for product add-ons.
When using options of the "Product" type, by default, the add-on quantity is independent of the main product quantity. However, you can enable this filter to multiply the add-on quantity by the main product quantity.
For example, if __return_true is added to this filter, when the main product quantity is set to 3 and the add-on quantity is set to 2, the add-on product will be added with quantity 6. This is useful in cases where a certain number of product add-ons should be added to each item of the main product.
Arguments
$use_quantity(bool): Whether add-on quantities are multiplied by the cart quantity.$product(\Barn2\Plugin\WC_Product_Options\Util\WC_Product): The WooCommerce product instance.
Example
add_filter( 'wc_product_options_addons_use_cart_quantity', '__return_true' );
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(\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_checkout_link_expiration
Adds a checkout link above the cart for shop managers to share the cart with customers.
This feature requires WooCommerce Store API to be active. The link includes a session token that allows customers to access the cart without logging in. Only shop managers can see this link.
Example
add_filter( 'wc_product_options_checkout_link_expiration', 'my_wc_product_options_checkout_link_expiration' );
function my_wc_product_options_checkout_link_expiration() {
// your code here...
}
wc_product_options_choice_label_price
Get display price for a an option choice.
Arguments
$product(\WC_Product):$choice_price(float):$display_area(string|null):
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( $product, $choice_price, $display_area ) {
// your code to alter $product here...
return $product;
}
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 true.
Example
add_filter( 'wc_product_options_create_upload_thumbnails', '__return_true' );
wc_product_options_dependent_item_quantity
Filters the cart item quantity display.
Product addons are part of the main product, so their quantity is disabled.
Arguments
$quantity_html(string):$dependent_cart_item_key(string):$dependent_cart_item(array):
Example
add_filter( 'wc_product_options_dependent_item_quantity', 'my_wc_product_options_dependent_item_quantity', 10, 3 );
function my_wc_product_options_dependent_item_quantity( $quantity_html, $dependent_cart_item_key, $dependent_cart_item ) {
// your code to alter $quantity_html here...
return $quantity_html;
}
wc_product_options_dependent_item_remove_link
Filters the cart item remove link.
Product addons are part of the main product, so removing them individually is not allowed.
Arguments
$link(string):$dependent_cart_item_key(string):
Example
add_filter( 'wc_product_options_dependent_item_remove_link', 'my_wc_product_options_dependent_item_remove_link', 10, 2 );
function my_wc_product_options_dependent_item_remove_link( $link, $dependent_cart_item_key ) {
// your code to alter $link here...
return $link;
}
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_exclude_image_options_from_gallery
Filter to exclude image options from the product gallery.
When an image option is set to switch the main product image to the choice image, this filter prevent those images from being added to the product gallery while still allowing the switch of the main product image to work.
Arguments
$exclude(bool): Whether to exclude the image options from the product gallery. Default false.$option(object): The option object.$product(\WC_Product): The current product object.
Example
add_filter( 'wc_product_options_exclude_image_options_from_gallery', 'my_wc_product_options_exclude_image_options_from_gallery', 10, 3 );
function my_wc_product_options_exclude_image_options_from_gallery( $exclude, $option, $product ) {
// your code to alter $exclude here...
return $exclude;
}
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_attributes
Filter the field attributes.
Field attributes are added to the `.wpo-field` wrapper element.
Arguments
$attributes(array): The array of attributes.$field(\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.$product(\WC_Product): The current product object.
Example
add_filter( 'wc_product_options_field_attributes', 'my_wc_product_options_field_attributes', 10, 3 );
function my_wc_product_options_field_attributes( $attributes, $field, $product ) {
// your code to alter $attributes here...
return $attributes;
}
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_css_classes
Filters the array with the CSS classes for the field.
Arguments
$classes(array): The array with the CSS classes.$field(\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.$product(\WC_Product): The current product object.
Example
add_filter( 'wc_product_options_field_css_classes', 'my_wc_product_options_field_css_classes', 10, 3 );
function my_wc_product_options_field_css_classes( $classes, $field, $product ) {
// your code to alter $classes here...
return $classes;
}
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_field_has_quantity_pickers
Determines if the field has quantity pickers enabled.
Example
add_filter( 'wc_product_options_field_has_quantity_pickers', 'my_wc_product_options_field_has_quantity_pickers' );
function my_wc_product_options_field_has_quantity_pickers() {
// your code here...
}
wc_product_options_field_validate
Run the validation filters.
Arguments
$value(mixed):$option_data(array):$is_valid(bool):
Example
add_filter( 'wc_product_options_field_validate', 'my_wc_product_options_field_validate', 10, 3 );
function my_wc_product_options_field_validate( $value, $option_data, $is_valid ) {
// your code to alter $value here...
return $value;
}
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_file_uploaded
Filter the file object after it has been successfully uploaded.
The file object is returned by this endpoint to the calling script.
Arguments
$file(array): The file object.$option(\Barn2\Plugin\WC_Product_Options\Model\Option): The option model.$file_data(array): The original file data from the $_FILES array.$request(\Barn2\Plugin\WC_Product_Options\Rest\Routes\WP_REST_Request): The current request object.
Example
add_filter( 'wc_product_options_file_uploaded', 'my_wc_product_options_file_uploaded', 10, 4 );
function my_wc_product_options_file_uploaded( $file, $option, $file_data, $request ) {
// your code to alter $file here...
return $file;
}
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_general_settings
Register the settings.
Example
add_filter( 'wc_product_options_general_settings', 'my_wc_product_options_general_settings' );
function my_wc_product_options_general_settings() {
// 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):
Example
add_filter( 'wc_product_options_get_frontend_string', 'my_wc_product_options_get_frontend_string', 10, 2 );
function my_wc_product_options_get_frontend_string( $string_value, $args ) {
// your code to alter $string_value here...
return $string_value;
}
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_number_default_decimals
Filter to override the default number of decimal places for a number field
when the `number_type` is set to `decimal`.
Please note that returning zero (0) will make the field behave like an integer field as if the `number_type` was set to `whole`.
Arguments
$decimals(int): The default number of decimal places. Default is 3.
Example
add_filter( 'wc_product_options_get_number_default_decimals', 'my_wc_product_options_get_number_default_decimals' );
function my_wc_product_options_get_number_default_decimals( $decimals ) {
// your code to alter $decimals here...
return $decimals;
}
wc_product_options_get_output_string
Filter the choice label before formatting.
Arguments
$choice_label(string):$option_object(\Barn2\Plugin\WC_Product_Options\Model\Option):$context(string):$choice_index(int|null):
Example
add_filter( 'wc_product_options_get_output_string', 'my_wc_product_options_get_output_string', 10, 4 );
function my_wc_product_options_get_output_string( $choice_label, $option_object, $context, $choice_index ) {
// your code to alter $choice_label here...
return $choice_label;
}
wc_product_options_get_price_html_priority
Filters the priority for the `woocommerce_get_price_html` filter used to modify the main product price display.
Many components modify the price HTML, so we use the highest priority to ensure our modification runs last but also allow developers to adjust this if needed.
Arguments
$priority(int): The priority for the filter.
Example
add_filter( 'wc_product_options_get_price_html_priority', 'my_wc_product_options_get_price_html_priority' );
function my_wc_product_options_get_price_html_priority( $priority ) {
// your code to alter $priority here...
return $priority;
}
wc_product_options_get_product_id
Get the groups for a particular product.
Arguments
$product(\WC_Product):
Example
add_filter( 'wc_product_options_get_product_id', 'my_wc_product_options_get_product_id' );
function my_wc_product_options_get_product_id( $product ) {
// your code to alter $product here...
return $product;
}
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_{$field_type}_{$setting_name}_setting
Filters the value of a specific field setting.
The variable portions of the filter name refer to: - the field type (e.g., `text` or `customer_price`), and - the setting name (e.g., `default_value`).
Arguments
$value(string): 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 1
add_filter( 'wc_product_options_get_text_default_value_setting', 'my_filter_text_default_value', 10, 3 );
function wc_product_options_get_field_type_setting_name_setting( $value, $field, $product ) {
return 'Custom default value';
}
Example 2
add_filter( 'wc_product_options_get_customer_price_min_price_setting', 'my_filter_customer_price_min_price', 10, 3 );
function wc_product_options_get_field_type_setting_name_setting( $value, $field, $product ) {
return 'Custom min price';
}
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_choice_preselected
Filters whether the choice is preselected.
Arguments
$is_selected(bool): True if the choice is preselected, false otherwise.$choice(array): The choice array.$field(\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.$product(\WC_Product): The current product object.
Example
add_filter( 'wc_product_options_is_choice_preselected', 'my_wc_product_options_is_choice_preselected', 10, 4 );
function my_wc_product_options_is_choice_preselected( $is_selected, $choice, $field, $product ) {
// your code to alter $is_selected here...
return $is_selected;
}
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
$show_in_product_gallery(bool): Whether the option has the "Update main image" setting enabled.$option(\Barn2\Plugin\WC_Product_Options\Fields\Image_Buttons): The current option object.$product(\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, 3 );
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_list_addons_before_main_product
Push products added with options to the bottom of the cart.
Products added with a Products option type field are added during the cart validation process, which results in them appearing above the main product when that is finally added to the cart. This method removes and re-adds those products so they appear at the bottom of the cart.
Arguments
$cart_item_key(string):$product_id(int):$quantity(int):$variation_id(int):$variation(array):$cart_item_data(array):
Example
add_filter( 'wc_product_options_list_addons_before_main_product', 'my_wc_product_options_list_addons_before_main_product', 10, 6 );
function my_wc_product_options_list_addons_before_main_product( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
// your code to alter $cart_item_key here...
return $cart_item_key;
}
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):
Example
add_filter( 'wc_product_options_multiple_cart_item_data_seperator', 'my_wc_product_options_multiple_cart_item_data_seperator' );
function my_wc_product_options_multiple_cart_item_data_seperator( $seperator ) {
// your code to alter $seperator here...
return $seperator;
}
wc_product_options_option_name_prefix
Filters the prefix added to the option name.
Arguments
$prefix(string): The prefix string.$field(\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.$product(\Barn2\Plugin\WC_Product_Options\Fields\WC_Product): The current product object.
Example
add_filter( 'wc_product_options_option_name_prefix', 'my_wc_product_options_option_name_prefix', 10, 3 );
function my_wc_product_options_option_name_prefix( $prefix, $field, $product ) {
// your code to alter $prefix here...
return $prefix;
}
wc_product_options_option_name_suffix
Filters the suffix added to the option name.
Arguments
$suffix(string): The suffix string.$field(\Barn2\Plugin\WC_Product_Options\Fields\Abstract_Field): The current field object.$product(\WC_Product): The current product object.
Example
add_filter( 'wc_product_options_option_name_suffix', 'my_wc_product_options_option_name_suffix', 10, 3 );
function my_wc_product_options_option_name_suffix( $suffix, $field, $product ) {
// your code to alter $suffix here...
return $suffix;
}
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_price_display_when_zero
Filters the price display format when the product price is zero.
This filter allows to override the price display format when the product price is zero, regardless of the group settings.
Arguments
$price_display_format(string): The price display format.$product(\WC_Product): The product.
Example
add_filter( 'wc_product_options_price_display_when_zero', 'my_wc_product_options_price_display_when_zero', 10, 2 );
function my_wc_product_options_price_display_when_zero( $price_display_format, $product ) {
// your code to alter $price_display_format here...
return $price_display_format;
}
wc_product_options_product_add_to_cart_button_text
Filter the add to cart button text.
Arguments
$add_to_cart_button_text(string): The add to cart button text.
Example
add_filter( 'wc_product_options_product_add_to_cart_button_text', 'my_wc_product_options_product_add_to_cart_button_text' );
function my_wc_product_options_product_add_to_cart_button_text( $add_to_cart_button_text ) {
// your code to alter $add_to_cart_button_text here...
return $add_to_cart_button_text;
}
wc_product_options_product_price_container
Filters the product price to display in the totals container.
Arguments
$price(float): The product price.$product(\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_quantity_picker_inline_position
Example
add_filter( 'wc_product_options_quantity_picker_inline_position', 'my_wc_product_options_quantity_picker_inline_position' );
function my_wc_product_options_quantity_picker_inline_position() {
// your code here...
}
wc_product_options_script_params
Example
add_filter( 'wc_product_options_script_params', 'my_wc_product_options_script_params' );
function my_wc_product_options_script_params() {
// your code here...
}
wc_product_options_searched_products
Filter the list of products so that other plugins can add or remove products.
Arguments
$products(array): The list of all products.$request(\Barn2\Plugin\WC_Product_Options\Rest\Routes\WP_REST_Request): The current request object.
Example
add_filter( 'wc_product_options_searched_products', 'my_wc_product_options_searched_products', 10, 2 );
function my_wc_product_options_searched_products( $products, $request ) {
// your code to alter $products here...
return $products;
}
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_shall_enqueue_frontend_assets
Filters whether to enqueue the front-end assets.
Arguments
$shall_enqueue(bool): True if the front-end assets should be enqueued, false otherwise.
Example
add_filter( 'wc_product_options_shall_enqueue_frontend_assets', 'my_wc_product_options_shall_enqueue_frontend_assets' );
function my_wc_product_options_shall_enqueue_frontend_assets( $shall_enqueue ) {
// your code to alter $shall_enqueue here...
return $shall_enqueue;
}
wc_product_options_show_one_error_per_field
Filters whether to show only one error message per field.
Validation may generate multiple error messages for a single field. This filter allows controlling whether to show all error messages or just one per field.
Arguments
$show_one_error(bool): Whether to show only one error message per field. Default true.
Example
add_filter( 'wc_product_options_show_one_error_per_field', '__return_false' );
wc_product_options_total_label
Filters the total label text.
Arguments
$total_label(string): The total label.$product(\WC_Product): The product object.
Example
add_filter( 'wc_product_options_total_label', 'my_wc_product_options_total_label', 10, 2 );
function my_wc_product_options_total_label( $total_label, $product ) {
// your code to alter $total_label here...
return $total_label;
}
wc_product_options_update_addons_with_parent
Filters whether to link addon changes to their parent item.
By default, dependent addon items will have their own quantities and remove buttons in the cart. However, if you want to link their quantities to the parent item (so they update automatically when the parent quantity changes), or you want them to be removed when the parent item is removed, you can enable this filter. You activate this behavior site-wide by returning true in the filter as in the following example: Alternatively, you can enable it conditionally based on the cart item or other criteria by using a custom callback function.
Arguments
$update(bool): Whether to update dependent addon items.$dependent_cart_item_key(string): The cart item key of the dependent cart item.$dependent_cart_item(array): The dependent cart item.$parent_cart_item_key(string): The key of the parent item.$parent_cart_item(array): The parent cart item.
Example
add_filter( 'wc_product_options_update_addons_with_parent', '__return_true' );
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.
Example
add_filter( 'wc_product_options_uploads_thumbnail_size', 'my_wc_product_options_uploads_thumbnail_size', 10, 2 );
function my_wc_product_options_uploads_thumbnail_size( $size, $file ) {
// your code to alter $size here...
return $size;
}
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' );