Actions and Filters
WooCommerce Wholesale Pro comes with some filters which allow you to customize the plugin's behavior.
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
wcwp_all_import_update_product
Triggered after WP All Import updates a product.
Arguments
$post_id
(int): The post_id of the product imported.
Example
add_action( 'wcwp_all_import_update_product', 'my_wcwp_all_import_update_product' );
function my_wcwp_all_import_update_product( $post_id ) {
// your code here...
}
wcwp_category_discount_changed
Triggered after the category discount is changed.
Arguments
$role_name
(string): The role where discounts where changed.
Example
add_action( 'wcwp_category_discount_changed', 'my_wcwp_category_discount_changed' );
function my_wcwp_category_discount_changed( $role_name ) {
// your code here...
}
wcwp_created_customer
Triggered after a customer is created following a successful registration.
Arguments
$customer_id
(int): The user_id of the created customer.$new_customer_data
(array): The customer data used to create the customer.
Example
add_action( 'wcwp_created_customer', 'my_wcwp_created_customer', 10, 2 );
function my_wcwp_created_customer( $customer_id, $new_customer_data ) {
// your code here...
}
wcwp_disable_wholesale_store_table_layout
Fires when the wholesale store layout is disabled.
This action is fired so that other adjustments can be made when a theme requires them.
wcwp_enable_wholesale_store_table_layout
Fires when the wholesale store layout is enabled.
This action is fired so that other adjustments can be made when a theme requires them.
wcwp_handle_404
Triggered after a 404 is handled for Public Only protection.
Example
add_action( 'wcwp_handle_404', 'my_wcwp_handle_404' );
function my_wcwp_handle_404() {
// your code here...
}
wcwp_new_user_auto_approved
Triggered if a new customer is created and auto approved.
Arguments
$customer_id
(int): The user_id of the customer.
Example
add_action( 'wcwp_new_user_auto_approved', 'my_wcwp_new_user_auto_approved' );
function my_wcwp_new_user_auto_approved( $customer_id ) {
// your code here...
}
wcwp_new_user_moderation
Triggered if a new customer is created and sent to moderation.
Arguments
$customer_id
(int): The user_id of the customer.
Example
add_action( 'wcwp_new_user_moderation', 'my_wcwp_new_user_moderation' );
function my_wcwp_new_user_moderation( $customer_id ) {
// your code here...
}
wcwp_prevent_caching
Triggered after cache prevention is processed on a protected page.
Example
add_action( 'wcwp_prevent_caching', 'my_wcwp_prevent_caching' );
function my_wcwp_prevent_caching() {
// your code here...
}
wcwp_prevent_caching_login_page
Triggered after cache prevention on wholesale login page.
Example
add_action( 'wcwp_prevent_caching_login_page', 'my_wcwp_prevent_caching_login_page' );
function my_wcwp_prevent_caching_login_page() {
// your code here...
}
wcwp_prevent_indexing
Triggered after search engine index prevention on protected pages.
Example
add_action( 'wcwp_prevent_indexing', 'my_wcwp_prevent_indexing' );
function my_wcwp_prevent_indexing() {
// your code here...
}
wcwp_price_handler_after_price_html
Outputs the wholesale price html
Arguments
$price_html
(string):$product
(\WC_Product):
Example
add_action( 'wcwp_price_handler_after_price_html', 'my_wcwp_price_handler_after_price_html', 10, 2 );
function my_wcwp_price_handler_after_price_html( $price_html, $product ) {
// your code here...
}
wcwp_price_handler_before_price_html
Outputs the wholesale price html
Arguments
$price_html
(string):$product
(\WC_Product):
Example
add_action( 'wcwp_price_handler_before_price_html', 'my_wcwp_price_handler_before_price_html', 10, 2 );
function my_wcwp_price_handler_before_price_html( $price_html, $product ) {
// your code here...
}
wcwp_protected_woocommerce_page
Triggered on 'wp' action if protection is enabled.
Example
add_action( 'wcwp_protected_woocommerce_page', 'my_wcwp_protected_woocommerce_page' );
function my_wcwp_protected_woocommerce_page() {
// your code here...
}
wcwp_register_post
Triggered before a registration is processed or failed.
Arguments
$username
(string): The username, generated from the email or provided by the user.$email
(string): The email address of the user.$errors
(\WP_Error): The error collector, if any externally hooked registration processes caused an error.
Example
add_action( 'wcwp_register_post', 'my_wcwp_register_post', 10, 3 );
function my_wcwp_register_post( $username, $email, $errors ) {
// your code here...
}
wcwp_role_details_updated
Triggered after a Wholesale Role is updated.
Arguments
$role_name
(string): The name of the role which was updated.$data
(array): The new data.
Example
add_action( 'wcwp_role_details_updated', 'my_wcwp_role_details_updated', 10, 2 );
function my_wcwp_role_details_updated( $role_name, $data ) {
// your code here...
}
wcwp_simple_pricing_changed
Triggered after the simple pricing has changed.
Arguments
$role_name
(string): The name of the role where pricing changed.$post_id
(int): The post_id of the product affected.$meta_name
(string): The meta_key being affected (the role name with or without the suffix `_sale` appended).
Example
add_action( 'wcwp_simple_pricing_changed', 'my_wcwp_simple_pricing_changed', 10, 3 );
function my_wcwp_simple_pricing_changed( $role_name, $post_id, $meta_name ) {
// your code here...
}
wcwp_update_registration_fields
Triggered when the registration fields are saved.
Example
add_action( 'wcwp_update_registration_fields', 'my_wcwp_update_registration_fields' );
function my_wcwp_update_registration_fields() {
// your code here...
}
wcwp_user_after_approved
Triggered after a pending customer is approved.
Arguments
$user_id
(int): The user_id of the approved customer.
Example
add_action( 'wcwp_user_after_approved', 'my_wcwp_user_after_approved' );
function my_wcwp_user_after_approved( $user_id ) {
// your code here...
}
wcwp_user_before_reject
Triggered after pending customer is rejected, but before deleted.
Arguments
$user_id
(int): The user_id of the rejected customer.
Example
add_action( 'wcwp_user_before_reject', 'my_wcwp_user_before_reject' );
function my_wcwp_user_before_reject( $user_id ) {
// your code here...
}
wcwp_variation_pricing_changed
Triggered after the variation pricing is updated.
Arguments
$role_name
(string): The name of the role where pricing changed.$variation_id
(int): The post_id of the variation affected.$meta_name
(string): The meta_key being affected (the role name with or without the suffix `_sale` appended).
Example
add_action( 'wcwp_variation_pricing_changed', 'my_wcwp_variation_pricing_changed', 10, 3 );
function my_wcwp_variation_pricing_changed( $role_name, $variation_id, $meta_name ) {
// your code here...
}
wcwp_wholesale_price_after_get_pricing
Retrieve the pricing for a product
Example
add_action( 'wcwp_wholesale_price_after_get_pricing', 'my_wcwp_wholesale_price_after_get_pricing' );
function my_wcwp_wholesale_price_after_get_pricing() {
// your code here...
}
wcwp_wholesale_price_before_get_pricing
Retrieve the pricing for a product
Example
add_action( 'wcwp_wholesale_price_before_get_pricing', 'my_wcwp_wholesale_price_before_get_pricing' );
function my_wcwp_wholesale_price_before_get_pricing() {
// your code here...
}
Filters
wcwp_admin_roles_description
Filter the wholesale roles description in the admin panel.
Arguments
$description
(string): The description text.
Example
add_filter( 'wcwp_admin_roles_description', 'my_wcwp_admin_roles_description' );
function my_wcwp_admin_roles_description( $description ) {
// your code to alter $description here...
return $description;
}
wcwp_block_password_reset
Filters whether password resets should be blocked when a user is in moderation.
Arguments
$block
(bool): Whether to block the password reset. (default: true)
Example
add_filter( 'wcwp_block_password_reset', 'my_wcwp_block_password_reset' );
function my_wcwp_block_password_reset( $block ) {
// your code to alter $block here...
return $block;
}
wcwp_calculate_wholesale_price_in_cart
Filters whether to calculate wholesale price in the cart.
Arguments
$should_calculate
(bool): Whether to calculate wholesale price in the cart.$cart
(\Barn2\Plugin\WC_Wholesale_Pro\Handlers\WC_Cart): The cart object.$role
(\Barn2\Plugin\WC_Wholesale_Pro\Controller\Wholesale_Role): The wholesale role object.
Example
add_filter( 'wcwp_calculate_wholesale_price_in_cart', 'my_wcwp_calculate_wholesale_price_in_cart', 10, 3 );
function my_wcwp_calculate_wholesale_price_in_cart( $should_calculate, $cart, $role ) {
// your code to alter $should_calculate here...
return $should_calculate;
}
wcwp_calculated_wholesale_price
Filters the calculated wholesale price for a product.
Arguments
$price
(float): The calculated price.$product
(\WC_Product): The WooCommerce product.$wholesale_role
(\Barn2\Plugin\WC_Wholesale_Pro\Controller\Wholesale_Role): The wholesale role object.
Example
add_filter( 'wcwp_calculated_wholesale_price', 'my_wcwp_calculated_wholesale_price', 10, 3 );
function my_wcwp_calculated_wholesale_price( $price, $product, $wholesale_role ) {
// your code to alter $price here...
return $price;
}
wcwp_calculated_wholesale_sale_price
Filters the calculated wholesale sale price for a product.
Arguments
$sale_price
(bool|string|float): The calculated sale price.$product
(\WC_Product): The WooCommerce product.$wholesale_role
(\Barn2\Plugin\WC_Wholesale_Pro\Controller\Wholesale_Role): The wholesale role object.
Example
add_filter( 'wcwp_calculated_wholesale_sale_price', 'my_wcwp_calculated_wholesale_sale_price', 10, 3 );
function my_wcwp_calculated_wholesale_sale_price( $sale_price, $product, $wholesale_role ) {
// your code to alter $sale_price here...
return $sale_price;
}
wcwp_category_current_user_allowed_by_role
Filters whether the wholesale user can view the category.
Arguments
$allowed
(bool): Whether the user is allowed to view. Default is true.$visibility
(string): The visibility type.$term_id
(int): The term_id of the category.
Example
add_filter( 'wcwp_category_current_user_allowed_by_role', 'my_wcwp_category_current_user_allowed_by_role', 10, 3 );
function my_wcwp_category_current_user_allowed_by_role( $allowed, $visibility, $term_id ) {
// your code to alter $allowed here...
return $allowed;
}
wcwp_category_nav_protector_items_to_remove
Filter the items to remove.
Arguments
$items_to_remove
(\WP_Post[]):$menu_items
(array):$menu
(string):$args
(array):
Example
add_filter( 'wcwp_category_nav_protector_items_to_remove', 'my_wcwp_category_nav_protector_items_to_remove', 10, 4 );
function my_wcwp_category_nav_protector_items_to_remove( $items_to_remove, $menu_items, $menu, $args ) {
// your code to alter $items_to_remove here...
return $items_to_remove;
}
wcwp_category_protection_priority_order
Filters the category protection priority.
Arguments
$protection_order
(string[]): The protections in order of priority. Default is `[ 'wholesale_only', 'public_only' ]`.
Example
add_filter( 'wcwp_category_protection_priority_order', 'my_wcwp_category_protection_priority_order' );
function my_wcwp_category_protection_priority_order( $protection_order ) {
// your code to alter $protection_order here...
return $protection_order;
}
wcwp_category_upsell_protected_ids
Protect upsells from being displayed if they are in a protected category.
Arguments
$ids
(array): Array of upsell IDs.
Example
add_filter( 'wcwp_category_upsell_protected_ids', 'my_wcwp_category_upsell_protected_ids' );
function my_wcwp_category_upsell_protected_ids( $ids ) {
// your code to alter $ids here...
return $ids;
}
wcwp_disregard_wholesale_pricing
Determine whether to disregard the wholesale pricing
Arguments
$product
(\WC_Product): The current product.
Example
add_filter( 'wcwp_disregard_wholesale_pricing', 'my_wcwp_disregard_wholesale_pricing' );
function my_wcwp_disregard_wholesale_pricing( $product ) {
// your code to alter $product here...
return $product;
}
wcwp_email_body_content_{$this_id}
Filters the body content of a wholesale email.
Arguments
$content
(string): The body content.$object
(object|bool): The object the email is for (e.g customer).$email
(\WC_Email): The email object.
Example
add_filter( 'wcwp_email_body_content_{$this_id}', 'my_wcwp_email_body_content_this_id', 10, 3 );
function my_wcwp_email_body_content_this_id( $content, $object, $email ) {
// your code to alter $content here...
return $content;
}
wcwp_enable_wholesale_price_calculation
Filters whether to allow wholesale price calculation on a product.
Arguments
$enable
(bool): Whether to allow wholesale price calculation on a product.$product
(\WC_Product): The product which is being calculated.$user
(\WP_User): The user for which the price is being calculated.$price
(float): The wholesale price.$cart_item
(array|null): The cart item if this is calculated in the cart.
Example
add_filter( 'wcwp_enable_wholesale_price_calculation', 'my_wcwp_enable_wholesale_price_calculation', 10, 5 );
function my_wcwp_enable_wholesale_price_calculation( $enable, $product, $user, $price, $cart_item ) {
// your code to alter $enable here...
return $enable;
}
wcwp_is_shipping_rate_hidden
Whether to hide the current shipping rate.
Arguments
$is_rate_hidden
(bool): Whether to hide the current shipping rate.$roles
(array): The user roles.$shipping_rate
(\WC_Shipping_Rate): The shipping rate being evaluated.$shipping_rates
(\WC_Shipping_Rate[]): All the available shipping rates.
Example
add_filter( 'wcwp_is_shipping_rate_hidden', 'my_wcwp_is_shipping_rate_hidden', 10, 4 );
function my_wcwp_is_shipping_rate_hidden( $is_rate_hidden, $roles, $shipping_rate, $shipping_rates ) {
// your code to alter $is_rate_hidden here...
return $is_rate_hidden;
}
wcwp_login_redirect
Filters the login redirect URL.
Arguments
$url
(string): The URL to redirect to.$user
(\WP_User): The user being redirected.
Example
add_filter( 'wcwp_login_redirect', 'my_wcwp_login_redirect', 10, 2 );
function my_wcwp_login_redirect( $url, $user ) {
// your code to alter $url here...
return $url;
}
wcwp_login_shortcode_tag
Filters the login shortcode tag.
Arguments
$tag
(string): The shortcode tag excluding the brackets.
Example
add_filter( 'wcwp_login_shortcode_tag', 'my_wcwp_login_shortcode_tag' );
function my_wcwp_login_shortcode_tag( $tag ) {
// your code to alter $tag here...
return $tag;
}
wcwp_prices_follow_tax_status
Example
add_filter( 'wcwp_prices_follow_tax_status', 'my_wcwp_prices_follow_tax_status' );
function my_wcwp_prices_follow_tax_status() {
// your code here...
}
wcwp_product_current_user_allowed_by_role
Filters whether the wholesale user can view the product.
Arguments
$allowed
(bool): Whether the user is allowed to view. Default is true.$visibility
(string): The visibility type.$term_id
(int): The term_id of the product.
Example
add_filter( 'wcwp_product_current_user_allowed_by_role', 'my_wcwp_product_current_user_allowed_by_role', 10, 3 );
function my_wcwp_product_current_user_allowed_by_role( $allowed, $visibility, $term_id ) {
// your code to alter $allowed here...
return $allowed;
}
wcwp_product_id_for_protection_check
Filters the product ID for a category protection check.
Arguments
$product_id
(int): The product ID.$product
(\WC_Product): The WC Product.
Example
add_filter( 'wcwp_product_id_for_protection_check', 'my_wcwp_product_id_for_protection_check', 10, 2 );
function my_wcwp_product_id_for_protection_check( $product_id, $product ) {
// your code to alter $product_id here...
return $product_id;
}
wcwp_product_is_on_sale
Determine whether a product is on sale based on the wholesale role of the user currently logged in
Arguments
$onsale
(bool):$product
(\WC_Product):
Example
add_filter( 'wcwp_product_is_on_sale', 'my_wcwp_product_is_on_sale', 10, 2 );
function my_wcwp_product_is_on_sale( $onsale, $product ) {
// your code to alter $onsale here...
return $onsale;
}
wcwp_product_nav_protector_items_to_remove
Filter the list of menu items to remove for product level visibility protection.
Arguments
$items_to_remove
(array):$menu_items
(array):$menu
(string):$args
(array):
Example
add_filter( 'wcwp_product_nav_protector_items_to_remove', 'my_wcwp_product_nav_protector_items_to_remove', 10, 4 );
function my_wcwp_product_nav_protector_items_to_remove( $items_to_remove, $menu_items, $menu, $args ) {
// your code to alter $items_to_remove here...
return $items_to_remove;
}
wcwp_product_price_transient_key
Filter the transient key name for a generated wholesale price on a product.
Arguments
$key
(string): The transient key.$product
(\WC_Product): The WooCommerce product.$wholesale_role
(\Barn2\Plugin\WC_Wholesale_Pro\Controller\Wholesale_Role): The wholesale role object.
Example
add_filter( 'wcwp_product_price_transient_key', 'my_wcwp_product_price_transient_key', 10, 3 );
function my_wcwp_product_price_transient_key( $key, $product, $wholesale_role ) {
// your code to alter $key here...
return $key;
}
wcwp_register_shortcode_tag
Filters the register shortcode tag.
Arguments
$tag
(string): The shortcode tag excluding the brackets.
Example
add_filter( 'wcwp_register_shortcode_tag', 'my_wcwp_register_shortcode_tag' );
function my_wcwp_register_shortcode_tag( $tag ) {
// your code to alter $tag here...
return $tag;
}
wcwp_skip_wholesale_calculations
Filters whether to skip wholesale calculations for a product altogether
before even running any additional checks.
Arguments
$skip
(bool): Whether to skip wholesale calculations.$product
(\WC_Product): The product which is being calculated.
Example
add_filter( 'wcwp_skip_wholesale_calculations', 'my_wcwp_skip_wholesale_calculations', 10, 2 );
function my_wcwp_skip_wholesale_calculations( $skip, $product ) {
// your code to alter $skip here...
return $skip;
}
wcwp_store_query_tax_query
Example
add_filter( 'wcwp_store_query_tax_query', 'my_wcwp_store_query_tax_query' );
function my_wcwp_store_query_tax_query() {
// your code here...
}
wcwp_widget_get_current_page_url
Filters the current page url with filtering properties.
Arguments
$link
(string): The calculated url.$widget
(\WC_Widget): The widget object.
Example
add_filter( 'wcwp_widget_get_current_page_url', 'my_wcwp_widget_get_current_page_url', 10, 2 );
function my_wcwp_widget_get_current_page_url( $link, $widget ) {
// your code to alter $link here...
return $link;
}