WooCommerce Discount Manager Actions and Filters
WooCommerce Discount Manager contains a number of hooks that you can use 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, we recommend posting a job on Codeable. We have partnered with them to provide plugin customizations for our customers.
Actions
wdm_after_set_cart_item_data
Hook: wdm_after_set_cart_item_data.
Fires after the cart item data is set.
Arguments
$cart_item
(array): The cart item.$original_price
(float): The original price.$new_price
(float): The new price.
wdm_applicable_discounts_registered
Action triggered when applicable discounts are registered.
Arguments
$discounts
(\Barn2\Plugin\Discount_Manager\Entities\Discount[]): The discounts that were applied to the cart (empty if none).$cart
(\WC_Cart): The cart object.
Example
add_action( 'wdm_applicable_discounts_registered', 'my_wdm_applicable_discounts_registered', 10, 2 );
function my_wdm_applicable_discounts_registered( $discounts, $cart ) {
// your code here...
}
wdm_before_set_cart_item_data
Hook: wdm_before_set_cart_item_data.
Fires before the cart item data is set.
Arguments
$cart_item
(array): The cart item.$original_price
(float): The original price.$new_price
(float): The new price.
wdm_cart_discount_added
Action triggered when all discounts are added to the cart.
Arguments
$discounts
(\Barn2\Plugin\Discount_Manager\Entities\Discount[]): The discounts that were applied to the cart.$cart
(\WC_Cart): The cart object.
Example
add_action( 'wdm_cart_discount_added', 'my_wdm_cart_discount_added', 10, 2 );
function my_wdm_cart_discount_added( $discounts, $cart ) {
// your code here...
}
wdm_discount_created
Action: fired after a discount is created.
Arguments
$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount):
Example
add_action( 'wdm_discount_created', 'my_wdm_discount_created' );
function my_wdm_discount_created( $discount ) {
// your code here...
}
wdm_discount_deleted
Action: fired after a discount is deleted.
Arguments
$discount_id
(string|int):
Example
add_action( 'wdm_discount_deleted', 'my_wdm_discount_deleted' );
function my_wdm_discount_deleted( $discount_id ) {
// your code here...
}
wdm_discount_duplicated
Action: fired after a discount is duplicated.
Arguments
$cloned_discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount): The newly created discount.
Example
add_action( 'wdm_discount_duplicated', 'my_wdm_discount_duplicated' );
function my_wdm_discount_duplicated( $cloned_discount ) {
// your code here...
}
wdm_discount_status_toggled
Action: fired after the activation status of a discount
has been toggled.
Arguments
$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount):$enabled
(bool):
Example
add_action( 'wdm_discount_status_toggled', 'my_wdm_discount_status_toggled', 10, 2 );
function my_wdm_discount_status_toggled( $discount, $enabled ) {
// your code here...
}
wdm_discount_updated
Action: fired after a discount is updated.
Arguments
$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount): The updated discount.
Example
add_action( 'wdm_discount_updated', 'my_wdm_discount_updated' );
function my_wdm_discount_updated( $discount ) {
// your code here...
}
wdm_discounts_reordered
Action: fired after the discounts have been reordered.
Arguments
$discounts
(array): The list of discounts.
Example
add_action( 'wdm_discounts_reordered', 'my_wdm_discounts_reordered' );
function my_wdm_discounts_reordered( $discounts ) {
// your code here...
}
Filters
wdm_applicable_discounts
Filter the applicable discounts.
Arguments
$discounts
(\Barn2\Plugin\Discount_Manager\Entities\Discount[]): The discounts.$cart
(\WC_Cart): The cart object.
Example
add_filter( 'wdm_applicable_discounts', 'my_wdm_applicable_discounts', 10, 2 );
function my_wdm_applicable_discounts( $discounts, $cart ) {
// your code to alter $discounts here...
return $discounts;
}
wdm_bulk_table_locations
Filter the list of locations where the bulk table can be displayed.
Arguments
$locations
(array): The list of locations.
Example
add_filter( 'wdm_bulk_table_locations', 'my_wdm_bulk_table_locations' );
function my_wdm_bulk_table_locations( $locations ) {
// your code to alter $locations here...
return $locations;
}
wdm_cart_notice
Filter the cart notice message.
Arguments
$notice
(string): The notice message.$messages
(array): The messages.
Example
add_filter( 'wdm_cart_notice', 'my_wdm_cart_notice', 10, 2 );
function my_wdm_cart_notice( $notice, $messages ) {
// your code to alter $notice here...
return $notice;
}
wdm_cart_total_discount_amount
Filters the total discount amount calculated for the cart.
Arguments
$discount_total
(float): The total discount amount.
Example
add_filter( 'wdm_cart_total_discount_amount', 'my_wdm_cart_total_discount_amount' );
function my_wdm_cart_total_discount_amount( $discount_total ) {
// your code to alter $discount_total here...
return $discount_total;
}
wdm_cart_total_discount_amount_output
Filter the output of the total discount amount.
Arguments
$output
(string): The output.$discount_total
(float): The total discount amount.
Example
add_filter( 'wdm_cart_total_discount_amount_output', 'my_wdm_cart_total_discount_amount_output', 10, 2 );
function my_wdm_cart_total_discount_amount_output( $output, $discount_total ) {
// your code to alter $output here...
return $output;
}
wdm_discount_get_elegible_categories_child_terms
Filter whether the discount is applicable to the child categories.
When true, the discount pulls in the child categories of the categories that are selected.
Arguments
$look_for_children
(bool): True if the discount is applicable to the children of the categories.$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount): The discount object.
wdm_discount_is_applicable_to_cart
Filter whether the discount is applicable to the cart as a whole.
Arguments
$applicable
(bool): True if the discount is applicable to the cart as a whole.$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount): The discount object.$cart
(\WC_Cart): The cart object.
Example
add_filter( 'wdm_discount_is_applicable_to_cart', 'my_wdm_discount_is_applicable_to_cart', 10, 3 );
function my_wdm_discount_is_applicable_to_cart( $applicable, $discount, $cart ) {
// your code to alter $applicable here...
return $applicable;
}
wdm_discount_is_applicable_to_order
Filter whether the discount is applicable to the order as a whole.
Arguments
$applicable
(bool): True if the discount is applicable to the order as a whole.$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount): The discount object.$order
(\WC_Order): The order object.
Example
add_filter( 'wdm_discount_is_applicable_to_order', 'my_wdm_discount_is_applicable_to_order', 10, 3 );
function my_wdm_discount_is_applicable_to_order( $applicable, $discount, $order ) {
// your code to alter $applicable here...
return $applicable;
}
wdm_display_total_savings
Filter: determine if the total savings should be displayed in the order totals.
Arguments
$should_display
(bool): True if the total savings should be displayed, false otherwise.$order_id
(int): The order ID.
Example
add_filter( 'wdm_display_total_savings', 'my_wdm_display_total_savings', 10, 2 );
function my_wdm_display_total_savings( $should_display, $order_id ) {
// your code to alter $should_display here...
return $should_display;
}
wdm_display_total_savings_in_order_totals
Filter: determine if the total savings should be displayed in the order item totals.
This is injected into the order item totals via the 'woocommerce_get_order_item_totals' filter. The content is then displayed on pages and in emails.
Arguments
$should_display
(bool): True if the total savings should be displayed, false otherwise.$total_rows
(array): The total rows.$order_id
(int): The order ID.
wdm_escape_discount_text
Filter whether to escape the discount text.
Arguments
$should_escape
(bool): Whether to escape the discount text.
Example
add_filter( 'wdm_escape_discount_text', 'my_wdm_escape_discount_text' );
function my_wdm_escape_discount_text( $should_escape ) {
// your code to alter $should_escape here...
return $should_escape;
}
wdm_get_elegible_discounts_for_product
Filter the elegible discounts for the product.
Arguments
$discounts
(array): The discounts.$product_id
(int): The product ID.
Example
add_filter( 'wdm_get_elegible_discounts_for_product', 'my_wdm_get_elegible_discounts_for_product', 10, 2 );
function my_wdm_get_elegible_discounts_for_product( $discounts, $product_id ) {
// your code to alter $discounts here...
return $discounts;
}
wdm_get_option
Filters the retrieval of an option.
Arguments
$value
(mixed): the original value.$key
(string): the key of the option being retrieved.$default
(mixed): default value if nothing is found.
Example
add_filter( 'wdm_get_option', 'my_wdm_get_option', 10, 3 );
function my_wdm_get_option( $value, $key, $default ) {
// your code to alter $value here...
return $value;
}
wdm_get_option_{$key}
Get an option
Looks to see if the specified setting exists, returns default if not.
Arguments
$key
(string): the key to retrieve.$default
(mixed): default value to use in case option is not available.
Example
add_filter( 'wdm_get_option_{$key}', 'my_wdm_get_option_key', 10, 2 );
function my_wdm_get_option_key( $key, $default ) {
// your code to alter $key here...
return $key;
}
wdm_get_product_price
Filter the product price.
Arguments
$price
(string): The price.$product
(\WC_Product): The product.$context
(string): The context. Defaults to 'view'. Accepts 'view' and 'edit'.
Example
add_filter( 'wdm_get_product_price', 'my_wdm_get_product_price', 10, 3 );
function my_wdm_get_product_price( $price, $product, $context ) {
// your code to alter $price here...
return $price;
}
wdm_get_published_discounts
Filter the list of published discounts that are currently enabled
and ordered by priority.
Arguments
$discounts
(\Barn2\Plugin\Discount_Manager\Entities\Discount[]): The list of discounts.
Example
add_filter( 'wdm_get_published_discounts', 'my_wdm_get_published_discounts' );
function my_wdm_get_published_discounts( $discounts ) {
// your code to alter $discounts here...
return $discounts;
}
wdm_get_published_discounts_cached
Filter whether to retrieve the list of published discounts from the cache.
Arguments
$is_cached_requested
(bool): Whether to retrieve the list of published discounts from the cache.
Example
add_filter( 'wdm_get_published_discounts_cached', 'my_wdm_get_published_discounts_cached' );
function my_wdm_get_published_discounts_cached( $is_cached_requested ) {
// your code to alter $is_cached_requested here...
return $is_cached_requested;
}
wdm_get_simple_sale_price_html
Filter the simple sale price HTML when a simple discount is applicable.
Arguments
$price_html
(string): The price HTML.$product
(\WC_Product): The product.$discount
(\Barn2\Plugin\Discount_Manager\Entities\Discount): The discount.$reduced_product
(\WC_Product): The reduced product.
Example
add_filter( 'wdm_get_simple_sale_price_html', 'my_wdm_get_simple_sale_price_html', 10, 4 );
function my_wdm_get_simple_sale_price_html( $price_html, $product, $discount, $reduced_product ) {
// your code to alter $price_html here...
return $price_html;
}
wdm_product_text_allowed_html
Filter the list of allowed HTML tags for the discount text.
Arguments
$allowed_html
(array): The list of allowed HTML tags.
Example
add_filter( 'wdm_product_text_allowed_html', 'my_wdm_product_text_allowed_html' );
function my_wdm_product_text_allowed_html( $allowed_html ) {
// your code to alter $allowed_html here...
return $allowed_html;
}
wdm_settings_tabs
Filters the settings tabs in the settings page.
Arguments
$settings_tabs
(array): The settings tabs.$this->plugin
(\Barn2\Plugin\Discount_Manager\Dependencies\Lib\Plugin\Licensed_Plugin): The plugin.
Example
add_filter( 'wdm_settings_tabs', 'my_wdm_settings_tabs', 10, 2 );
function my_wdm_settings_tabs( $settings_tabs, $this->plugin ) {
// your code to alter $settings_tabs here...
return $settings_tabs;
}
wdm_should_show_sale_price
Filter whether to show the sale price for a product when a simple discount is applicable.
Arguments
$should_show
(bool): Whether to show the sale price.$product
(bool|\WC_Product): The product.
Example
add_filter( 'wdm_should_show_sale_price', 'my_wdm_should_show_sale_price', 10, 2 );
function my_wdm_should_show_sale_price( $should_show, $product ) {
// your code to alter $should_show here...
return $should_show;
}
wdm_update_option
Filter the final value of an option before being saved into the database.
Arguments
$value
(mixed): the value about to be saved.$key
(string): the key of the option that is being saved.
Example
add_filter( 'wdm_update_option', 'my_wdm_update_option', 10, 2 );
function my_wdm_update_option( $value, $key ) {
// your code to alter $value here...
return $value;
}