The documentation for WooCommerce Blocks has moved to the WooCommerce monorepo.
Please refer to the documentation in the new location as the files in this repository will no longer be updated and the repository will be archived.
- __experimental_woocommerce_blocks_add_data_attributes_to_block
- __experimental_woocommerce_blocks_add_data_attributes_to_namespace
- __experimental_woocommerce_blocks_payment_gateway_features_list
- deprecated_function_trigger_error
- loop_shop_per_page
- wc_session_expiration
- woocommerce_add_cart_item
- woocommerce_add_cart_item_data
- woocommerce_add_to_cart_quantity
- woocommerce_add_to_cart_sold_individually_quantity
- woocommerce_add_to_cart_validation
- woocommerce_adjust_non_base_location_prices
- woocommerce_apply_base_tax_for_local_pickup
- woocommerce_apply_individual_use_coupon
- woocommerce_apply_with_individual_use_coupon
- woocommerce_blocks_hook_compatibility_additional_data
- woocommerce_blocks_product_grid_is_cacheable
- woocommerce_blocks_product_grid_item_html
- woocommerce_blocks_register_script_dependencies
- woocommerce_cart_contents_changed
- woocommerce_cart_item_permalink
- woocommerce_disable_compatibility_layer
- woocommerce_ga_disable_tracking
- woocommerce_get_item_data
- woocommerce_loop_add_to_cart_args
- woocommerce_loop_add_to_cart_link
- woocommerce_new_customer_data
- woocommerce_pay_order_product_has_enough_stock
- woocommerce_pay_order_product_in_stock
- woocommerce_registration_errors
- woocommerce_shared_settings
- woocommerce_shipping_package_name
- woocommerce_shipping_{$this->id}_is_available
- woocommerce_show_page_title
- woocommerce_single_product_image_thumbnail_html
- woocommerce_store_api_add_to_cart_data
- woocommerce_store_api_disable_nonce_check
- woocommerce_store_api_product_quantity_limit
- woocommerce_store_api_product_quantity_{$value_type}
- woocommerce_store_api_rate_limit_options
Filters the list of allowed Block Names
apply_filters( '__experimental_woocommerce_blocks_add_data_attributes_to_block', array $allowed_namespaces )
This hook defines which block names should have block name and attribute data- attributes appended on render.
Argument | Type | Description |
---|---|---|
$allowed_namespaces | array | List of namespaces. |
Filters the list of allowed block namespaces.
apply_filters( '__experimental_woocommerce_blocks_add_data_attributes_to_namespace', array $allowed_namespaces )
This hook defines which block namespaces should have block name and attribute data-
attributes appended on render.
Argument | Type | Description |
---|---|---|
$allowed_namespaces | array | List of namespaces. |
Filter to control what features are available for each payment gateway.
apply_filters( '__experimental_woocommerce_blocks_payment_gateway_features_list', array $features, string $name )
Argument | Type | Description |
---|---|---|
$features | array | List of supported features. |
$name | string | Gateway name. |
array
Updated list of supported features.
// The action callback function.
function my_function_callback( $features, $gateway ) {
if ( 'my-gateway' !== $gateway->id ) {
return $features;
}
$features[] = 'some-feature';
return $features;
}
add_filter( '__experimental_woocommerce_blocks_payment_gateway_features_list', 'my_function_callback', 10, 2 );
Filters whether to trigger an error for deprecated functions. (Same as WP core)
apply_filters( 'deprecated_function_trigger_error', bool $trigger )
Argument | Type | Description |
---|---|---|
$trigger | bool | Whether to trigger the error for deprecated functions. Default true. |
apply_filters( 'loop_shop_per_page' )
Filters the session expiration.
apply_filters( 'wc_session_expiration', int $expiration )
Argument | Type | Description |
---|---|---|
$expiration | int | Expiration in seconds. |
Filters the item being added to the cart.
apply_filters( 'woocommerce_add_cart_item', array $cart_item_data, string $cart_id )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$cart_item_data | array | Array of cart item data being added to the cart. |
$cart_id | string | Id of the item in the cart. |
array
Updated cart item data.
Filter cart item data for add to cart requests.
apply_filters( 'woocommerce_add_cart_item_data', array $cart_item_data, integer $product_id, integer $variation_id, integer $quantity )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$cart_item_data | array | Array of other cart item data. |
$product_id | integer | ID of the product added to the cart. |
$variation_id | integer | Variation ID of the product added to the cart. |
$quantity | integer | Quantity of the item added to the cart. |
array
Filters the change the quantity to add to cart.
apply_filters( 'woocommerce_add_to_cart_quantity', \Automattic\WooCommerce\Blocks\BlockTypes\number $default_quantity, \Automattic\WooCommerce\Blocks\BlockTypes\number $product_id )
Argument | Type | Description |
---|---|---|
$default_quantity | \Automattic\WooCommerce\Blocks\BlockTypes\number | The default quantity. |
$product_id | \Automattic\WooCommerce\Blocks\BlockTypes\number | The product id. |
Filter sold individually quantity for add to cart requests.
apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', integer $sold_individually_quantity, integer $quantity, integer $product_id, integer $variation_id, array $cart_item_data )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$sold_individually_quantity | integer | Defaults to 1. |
$quantity | integer | Quantity of the item added to the cart. |
$product_id | integer | ID of the product added to the cart. |
$variation_id | integer | Variation ID of the product added to the cart. |
$cart_item_data | array | Array of other cart item data. |
integer
Filters if an item being added to the cart passed validation checks.
apply_filters( 'woocommerce_add_to_cart_validation', boolean $passed_validation, integer $product_id, integer $quantity, integer $variation_id, array $variation )
Deprecated: This hook is deprecated and will be removed
Allow 3rd parties to validate if an item can be added to the cart. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to exceptions instead.
Argument | Type | Description |
---|---|---|
$passed_validation | boolean | True if the item passed validation. |
$product_id | integer | Product ID being validated. |
$quantity | integer | Quantity added to the cart. |
$variation_id | integer | Variation ID being added to the cart. |
$variation | array | Variation data. |
boolean
Filters if taxes should be removed from locations outside the store base location.
apply_filters( 'woocommerce_adjust_non_base_location_prices', boolean $adjust_non_base_location_prices )
Note: Matches filter name in WooCommerce core.
The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.
Argument | Type | Description |
---|---|---|
$adjust_non_base_location_prices | boolean | True by default. |
boolean
apply_filters( 'woocommerce_apply_base_tax_for_local_pickup' )
Filter coupons to remove when applying an individual use coupon.
apply_filters( 'woocommerce_apply_individual_use_coupon', array $coupons, \WC_Coupon $coupon, array $applied_coupons )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$coupons | array | Array of coupons to remove from the cart. |
$coupon | \WC_Coupon | Coupon object applied to the cart. |
$applied_coupons | array | Array of applied coupons already applied to the cart. |
array
Filters if a coupon can be applied alongside other individual use coupons.
apply_filters( 'woocommerce_apply_with_individual_use_coupon', boolean $apply_with_individual_use_coupon, \WC_Coupon $coupon, \WC_Coupon $individual_use_coupon, array $applied_coupons )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$apply_with_individual_use_coupon | boolean | Defaults to false. |
$coupon | \WC_Coupon | Coupon object applied to the cart. |
$individual_use_coupon | \WC_Coupon | Individual use coupon already applied to the cart. |
$applied_coupons | array | Array of applied coupons already applied to the cart. |
boolean
When extensions implement their equivalent blocks of the template hook functions, they can use this filter to register their old hooked data here, so in the blockified template, the old hooked functions can be removed in favor of the new blocks while keeping the old hooked functions working in classic templates.
apply_filters( 'woocommerce_blocks_hook_compatibility_additional_data', array $data )
Accepts an array of hooked data. The array should be in the following format: [ [ hook => , function => , priority => , ], ... ] Where:
- hook-name is the name of the hook that have the functions hooked to.
- function-name is the hooked function name.
- priority is the priority of the hooked function.
Argument | Type | Description |
---|---|---|
$data | array | Additional hooked data. Default to empty |
Filters whether or not the product grid is cacheable.
apply_filters( 'woocommerce_blocks_product_grid_is_cacheable', boolean $is_cacheable, array $query_args )
Argument | Type | Description |
---|---|---|
$is_cacheable | boolean | The list of script dependencies. |
$query_args | array | Query args for the products query passed to BlocksWpQuery. |
array
True to enable cache, false to disable cache.
Filters the HTML for products in the grid.
apply_filters( 'woocommerce_blocks_product_grid_item_html', string $html, array $data, \WC_Product $product )
Argument | Type | Description |
---|---|---|
$html | string | Product grid item HTML. |
$data | array | Product data passed to the template. |
$product | \WC_Product | Product object. |
string
Updated product grid item HTML.
Filters the list of script dependencies.
apply_filters( 'woocommerce_blocks_register_script_dependencies', array $dependencies, string $handle )
Argument | Type | Description |
---|---|---|
$dependencies | array | The list of script dependencies. |
$handle | string | The script's handle. |
array
Filters the entire cart contents when the cart changes.
apply_filters( 'woocommerce_cart_contents_changed', array $cart_contents )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$cart_contents | array | Array of all cart items. |
array
Updated array of all cart items.
Filter the product permalink.
apply_filters( 'woocommerce_cart_item_permalink', string $product_permalink, array $cart_item, string $cart_item_key )
This is a hook taken from the legacy cart/mini-cart templates that allows the permalink to be changed for a product. This is specific to the cart endpoint.
Argument | Type | Description |
---|---|---|
$product_permalink | string | Product permalink. |
$cart_item | array | Cart item array. |
$cart_item_key | string | Cart item key. |
Filter to disable the compatibility layer for the blockified templates.
apply_filters( 'woocommerce_disable_compatibility_layer', \Automattic\WooCommerce\Blocks\Templates\boolean. $argument0 )
This hook allows to disable the compatibility layer for the blockified.
Argument | Type | Description |
---|---|---|
1 | \Automattic\WooCommerce\Blocks\Templates\boolean. |
Filter to disable Google Analytics tracking.
apply_filters( 'woocommerce_ga_disable_tracking', boolean $disable_tracking )
Note: Matches filter name in GA extension.
Argument | Type | Description |
---|---|---|
$disable_tracking | boolean | If true, tracking will be disabled. |
Filters cart item data.
apply_filters( 'woocommerce_get_item_data', array $item_data, array $cart_item )
Note: Matches filter name in WooCommerce core.
Filters the variation option name for custom option slugs.
Argument | Type | Description |
---|---|---|
$item_data | array | Cart item data. Empty by default. |
$cart_item | array | Cart item array. |
array
Allow filtering of the add to cart button arguments.
apply_filters( 'woocommerce_loop_add_to_cart_args' )
Filters the add to cart button class.
apply_filters( 'woocommerce_loop_add_to_cart_link', string $class )
Argument | Type | Description |
---|---|---|
$class | string | The class. |
Filters customer data before a customer account is registered.
apply_filters( 'woocommerce_new_customer_data', array $add_to_cart_data )
This hook filters customer data. It allows user data to be changed, for example, username, password, email, first name, last name, and role.
Argument | Type | Description |
---|---|---|
$customer_data | array | An array of customer (user) data. |
array
Filters whether or not the product has enough stock.
apply_filters( 'woocommerce_pay_order_product_has_enough_stock', boolean $argument0, \WC_Product $product, \WC_Order $order )
Argument | Type | Description |
---|---|---|
1 | boolean | True if has enough stock. |
$product | \WC_Product | Product. |
$order | \WC_Order | Order. |
Filters whether or not the product is in stock for this pay for order.
apply_filters( 'woocommerce_pay_order_product_in_stock', boolean $argument0, \WC_Product $product, \WC_Order $order )
Argument | Type | Description |
---|---|---|
1 | boolean | True if in stock. |
$product | \WC_Product | Product. |
$order | \WC_Order | Order. |
Filters registration errors before a customer account is registered.
apply_filters( 'woocommerce_registration_errors', \WP_Error $errors, string $username, string $user_email )
Note: Matches filter name in WooCommerce core.
This hook filters registration errors. This can be used to manipulate the array of errors before they are displayed.
Argument | Type | Description |
---|---|---|
$errors | \WP_Error | Error object. |
$username | string | Customer username. |
$user_email | string | Customer email address. |
\WP_Error
Filters the array of shared settings.
apply_filters( 'woocommerce_shared_settings', array $data )
Deprecated: This hook is deprecated and will be removed
Low level hook for registration of new data late in the cycle. This is deprecated. Instead, use the data api:
Automattic\WooCommerce\Blocks\Package::container()->get( Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class )->add( $key, $value )
Argument | Type | Description |
---|---|---|
$data | array | Settings data. |
array
Filters the shipping package name.
apply_filters( 'woocommerce_shipping_package_name', string $shipping_package_name, string $package_id, array $package )
Note: Matches filter name in WooCommerce core.
Argument | Type | Description |
---|---|---|
$shipping_package_name | string | Shipping package name. |
$package_id | string | Shipping package ID. |
$package | array | Shipping package from WooCommerce. |
string
Shipping package name.
apply_filters( 'woocommerce_shipping_{$this->id}_is_available' )
Hook: woocommerce_show_page_title
apply_filters( 'woocommerce_show_page_title' )
Allows controlling the display of the page title.
Filter the HTML markup for a single product image thumbnail in the gallery.
apply_filters( 'woocommerce_single_product_image_thumbnail_html', string $thumbnail_html, int $attachment_id )
Argument | Type | Description |
---|---|---|
$thumbnail_html | string | The HTML markup for the thumbnail. |
$attachment_id | int | The attachment ID of the thumbnail. |
Filters cart item data sent via the API before it is passed to the cart controller.
apply_filters( 'woocommerce_store_api_add_to_cart_data', array $customer_data )
This hook filters cart items. It allows the request data to be changed, for example, quantity, or supplemental cart item data, before it is passed into CartController::add_to_cart and stored to session.
CartController::add_to_cart only expects the keys id, quantity, variation, and cart_item_data, so other values may be ignored. CartController::add_to_cart (and core) do already have a filter hook called woocommerce_add_cart_item, but this does not have access to the original Store API request like this hook does.
Argument | Type | Description |
---|---|---|
$customer_data | array | An array of customer (user) data. |
array
Filters the Store API nonce check.
apply_filters( 'woocommerce_store_api_disable_nonce_check', boolean $disable_nonce_check )
This can be used to disable the nonce check when testing API endpoints via a REST API client.
Argument | Type | Description |
---|---|---|
$disable_nonce_check | boolean | If true, nonce checks will be disabled. |
boolean
Filters the quantity limit for a product being added to the cart via the Store API.
apply_filters( 'woocommerce_store_api_product_quantity_limit', integer $quantity_limit, \WC_Product $product )
Filters the variation option name for custom option slugs.
Argument | Type | Description |
---|---|---|
$quantity_limit | integer | Quantity limit which defaults to 9999 unless sold individually. |
$product | \WC_Product | Product instance. |
integer
Filters the quantity minimum for a cart item in Store API. This allows extensions to control the minimum qty of items already within the cart.
apply_filters( 'woocommerce_store_api_product_quantity_{$value_type}', mixed $value, \WC_Product $product, array|null $cart_item )
The suffix of the hook will vary depending on the value being filtered. For example, minimum, maximum, multiple_of, editable.
Argument | Type | Description |
---|---|---|
$value | mixed | The value being filtered. |
$product | \WC_Product | The product object. |
$cart_item | array, null | The cart item if the product exists in the cart, or null. |
mixed
Filters options for Rate Limits.
apply_filters( 'woocommerce_store_api_rate_limit_options', array $rate_limit_options )
Argument | Type | Description |
---|---|---|
$rate_limit_options | array | Array of option values. |
array
We're hiring! Come work with us!
🐞 Found a mistake, or have a suggestion? Leave feedback about this document here.