ulgm_hide_bulk_discount_info
Filters whether to hide bulk discount information from the user interface, allowing for custom display logic.
add_filter( 'ulgm_hide_bulk_discount_info', $callback, 10, 1 );
Description
Filters whether to display bulk discount information. By default, this information is shown when applicable. Developers can return `false` to prevent the discount details from being displayed. This hook is useful for customizing the user experience and hiding discounts under specific conditions.
Usage
add_filter( 'ulgm_hide_bulk_discount_info', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of using the ulgm_hide_bulk_discount_info filter to conditionally hide bulk discount information.
*
* This example will hide the bulk discount information if the current user is a logged-in administrator.
*
* @param bool $hide_discount Whether to hide the bulk discount information. Default is false.
* @return bool Whether to hide the bulk discount information.
*/
add_filter( 'ulgm_hide_bulk_discount_info', 'my_custom_hide_bulk_discount_info', 10, 1 );
function my_custom_hide_bulk_discount_info( $hide_discount ) {
// Check if the current user has the 'administrator' role.
if ( current_user_can( 'administrator' ) ) {
// If the user is an administrator, return true to hide the discount information.
return true;
}
// Otherwise, return the original value of $hide_discount.
return $hide_discount;
}
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:701
private function get_discount_info( $original_price, $discounted_price ) {
$user_id = wp_get_current_user()->ID;
$transient = SharedFunctions::get_transient_cache( '_ulgm_user_buy_courses_' . $user_id . '_order', $user_id );
// only show bulk discount of adding seats,
// not when adding buy courses
if ( ! empty( $transient ) ) {
return $this->get_changed_course_info( $transient );
}
if ( apply_filters( 'ulgm_hide_bulk_discount_info', false ) ) {
return '';
}
$discount_percentage = ( 1 - $discounted_price / $original_price ) * 100;
// To avoid 0% on screen
if ( 0 === $discount_percentage ) {
return '';
}
$discount_info_format = __(
'<br><small>%1$s: %2$s<br />%3$s: %4$s (%5$s%% %6$s)</small>',
'uncanny-learndash-groups'
);
return sprintf(
$discount_info_format,
__( 'Original price', 'uncanny-learndash-groups' ),
wc_price( $original_price ),
__( 'Bulk price', 'uncanny-learndash-groups' ),
wc_price( $discounted_price ),
number_format( $discount_percentage, 0 ),
__( 'off', 'uncanny-learndash-groups' )
);
}