Filter uncanny-learndash-groups

ulgm_show_per_seat_with_qty

Filters whether to show per-seat pricing with quantity for cart items.

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

Description

This filter hook controls whether to display per-seat quantity information for license products in the WooCommerce cart. Developers can return `false` to hide this information. It fires after determining if a cart item is a license product and before rendering the quantity.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Modifies the 'ulgm_show_per_seat_with_qty' filter to conditionally
 * display the "per seat" text based on product meta.
 *
 * This example demonstrates how a plugin developer might interact with
 * the 'ulgm_show_per_seat_with_qty' hook. It checks if the product associated
 * with the cart item has a custom meta key that dictates whether "per seat"
 * quantity should be displayed.
 *
 * @param bool   $show_per_seat Whether to show the "per seat" text. Default true.
 * @param array  $cart_item     The current cart item data.
 * @param string $cart_item_key The key for the current cart item.
 *
 * @return bool The modified value for $show_per_seat.
 */
add_filter( 'ulgm_show_per_seat_with_qty', function( $show_per_seat, $cart_item, $cart_item_key ) {
	// Ensure we have valid cart item data.
	if ( empty( $cart_item ) || ! isset( $cart_item['data'] ) || ! $cart_item['data'] instanceof WC_Product ) {
		return $show_per_seat;
	}

	$product = $cart_item['data'];

	// Check for a custom meta key that might disable "per seat" display.
	// For example, a product might have '_ulgm_hide_per_seat_qty' set to 'yes'.
	$hide_per_seat = $product->get_meta( '_ulgm_hide_per_seat_qty' );

	if ( 'yes' === $hide_per_seat ) {
		// If the meta indicates to hide, override the default and return false.
		return false;
	}

	// Otherwise, let the original filter value (or any other filters applied) determine.
	return $show_per_seat;
}, 10, 3 );

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-license.php:562

public function woocommerce_cart_item_qty_func( $qty, $cart_item, $cart_item_key ) {
		if ( empty( $cart_item ) ) {
			return $qty;
		}
		$product = $cart_item['data'];
		if ( ! $product instanceof WC_Product || ! $product->is_type( 'license' ) ) {
			return $qty;
		}
		if ( true === apply_filters( 'ulgm_show_per_seat_with_qty', true, $cart_item, $cart_item_key ) ) {
			$per_seat_text = get_option( 'ulgm_per_seat_text_plural', 'Seats' );
			$qty           = apply_filters(
				'ulgm_per_seat_text_with_qty',
				sprintf(
					'%s %s',
					$qty,
					$per_seat_text
				),
				$qty,
				$per_seat_text
			);
		}

		return $qty;
	}


Scroll to Top