ulgm_hide_bulk_discount_info_in_cart
Filters whether to hide bulk discount information displayed in the cart, allowing customization.
add_filter( 'ulgm_hide_bulk_discount_info_in_cart', $callback, 10, 1 );
Description
This filter hook allows developers to conditionally hide bulk discount information displayed in the WooCommerce cart. By returning `true` from this filter, you can prevent the discount notes from appearing alongside product names. This provides granular control over the cart's presentation for bulk discount scenarios.
Usage
add_filter( 'ulgm_hide_bulk_discount_info_in_cart', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
// Example: Conditionally hide bulk discount information if a specific user role is logged in.
add_filter( 'ulgm_hide_bulk_discount_info_in_cart', function( $hide ) {
// Check if WooCommerce is active and a user is logged in.
if ( class_exists( 'WooCommerce' ) && is_user_logged_in() ) {
$user = wp_get_current_user();
// If the user has the 'wholesale_customer' role, hide the discount info.
if ( in_array( 'wholesale_customer', (array) $user->roles ) ) {
return true; // Return true to hide the discount information.
}
}
return $hide; // Otherwise, return the original value (false by default).
}, 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/woocommerce/woocommerce-bulk-discount.php:579
public function display_discount_info_in_cart( $product_name = '', $values = array(), $cart_item_key = '' ) {
if ( ! isset( $values['bulk_discount_note'] ) ) {
return $product_name;
}
if ( apply_filters( 'ulgm_hide_bulk_discount_info_in_cart', false ) ) {
return $product_name;
}
$original_price = $values['data']->get_regular_price();
$discounted_price = $values['data']->get_price();
$product_name .= $this->get_discount_info( $original_price, $discounted_price );
return $product_name;
}