Filter uncanny-learndash-groups

ulgm_hide_bulk_discount_info_in_order_details

Filters whether to hide bulk discount information in order details, allowing customization of displayed discounts.

add_filter( 'ulgm_hide_bulk_discount_info_in_order_details', $callback, 10, 1 );

Description

Filters whether bulk discount information is displayed in WooCommerce order details. Return true to hide the discount note and original price from the order item name. This filter fires before discount details are processed for display, allowing developers to customize the visibility of this information.


Usage

add_filter( 'ulgm_hide_bulk_discount_info_in_order_details', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Conditionally hide bulk discount information in order details.
 *
 * This filter allows developers to programmatically hide the bulk discount
 * details (like the discount note and price adjustments) that are normally
 * displayed in WooCommerce order details.
 *
 * @param bool $hide_discount_info Whether to hide the discount information.
 *                                 Defaults to false (show discount information).
 * @return bool The modified value for hiding discount information.
 */
add_filter( 'ulgm_hide_bulk_discount_info_in_order_details', function( $hide_discount_info ) {

    // Example: Hide discount info if the user is an administrator.
    // This is just an illustrative example; real-world logic might be more complex.
    if ( current_user_can( 'manage_options' ) ) {
        return true; // Hide the discount information for administrators
    }

    // Example: Hide discount info for orders placed on a specific day of the week.
    // if ( date('N') === '5' ) { // Hide on Fridays
    //     return true;
    // }

    // If none of the conditions are met, return the original value
    // or false to display the discount information.
    return $hide_discount_info;
}, 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:665

public function display_discount_info_in_order( $item_name = '', $item = null, $is_visible = false ) {

		if ( apply_filters( 'ulgm_hide_bulk_discount_info_in_order_details', false ) ) {
			return $item_name;
		}

		if ( null === $item ) {
			return $item_name;
		}

		// Retrieve the saved meta data
		$bulk_discount_note = $item->get_meta( '_bulk_discount_note', true );
		$original_price     = $item->get_meta( '_original_price', true );
		$discounted_price   = $item->get_meta( '_discounted_price', true );

		if ( ! empty( $bulk_discount_note ) ) {
			$item_name .= $this->get_discount_info( $original_price, $discounted_price );
		}

		return $item_name;
	}

Scroll to Top