Filter uncanny-learndash-groups

ulgm_group_name_placeholder

Filters the placeholder text for the group name input field, allowing customization of the default "Enter group name" text.

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

Description

This filter hook allows developers to modify the default placeholder text for the "group name" input field on the WooCommerce checkout page. It enables customization of the placeholder displayed to users when entering group names.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Modify the placeholder text for the group name field on the WooCommerce checkout.
 *
 * This example appends the product title to the default placeholder to provide more context.
 *
 * @param string $placeholder The default placeholder text for the group name field.
 * @return string The modified placeholder text.
 */
add_filter( 'ulgm_group_name_placeholder', function( $placeholder ) {

	// In a real-world scenario, you'd likely have access to cart item data here.
	// For demonstration purposes, we'll simulate getting a product title.
	// This might involve accessing global variables like $woocommerce->cart if this
	// filter is fired within a context where the cart is available.

	// Let's assume we're within a loop or have a way to get the current product's title.
	// In the provided source context, the filter is applied inside a loop:
	// foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
	// ...
	// 'placeholder' => apply_filters( 'ulgm_group_name_placeholder', __( 'Enter group name', 'uncanny-learndash-groups' ) ),
	// ...
	// }
	// So, we'll assume $cart_item['data']->get_title() is available.

	// If the filter is called outside of the cart loop or without cart data,
	// we might fallback to the original placeholder.
	$current_product_title = '';
	if ( isset( $cart_item ) && isset( $cart_item['data'] ) && is_a( $cart_item['data'], 'WC_Product' ) ) {
		$current_product_title = $cart_item['data']->get_title();
	}

	if ( ! empty( $current_product_title ) ) {
		// Append the product title to the placeholder for better clarity.
		return sprintf(
			'%s: %s',
			$placeholder, // Original placeholder like 'Enter group name'
			$current_product_title
		);
	}

	// If no product title is available, return the original placeholder.
	return $placeholder;

}, 10, 1 ); // 10 is the priority, 1 is the number of accepted arguments.

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:2067

public function add_group_name_field_checkout( $checkout ) {

		if ( WoocommerceModifyGroup::is_modifying_license() ) {
			return;
		}

		if ( apply_filters( 'ulgm_woocommerce_hide_group_name_fields', false ) ) {
			return;
		}

		if ( 'yes' === get_option( 'ulgm_hide_edit_group_name_fields', 'no' ) ) {
			return;
		}

		$has_license_product = $this->check_if_license_product_in_cart();
		if ( class_exists( 'uncanny_learndash_groupsWoocommerceLicenseSubscription' ) ) {
			$has_license_subscription = WoocommerceLicenseSubscription::check_if_course_subscription_in_cart();
		} else {
			$has_license_subscription = array( 'status' => false );
		}

		// No license / subscription license found. Bail
		if ( ! isset( $has_license_subscription['status'] ) && ! isset( $has_license_product['status'] ) ) {
			return;
		}

		// No license / subscription license found. Bail
		if ( false === $has_license_product['status'] && false === $has_license_subscription['status'] ) {
			return;
		}

		echo apply_filters( 'ulgm_woocommerce_group_name_heading', '<div id="group_name_checkout_field"><h3>' . __( 'Group Name(s)', 'uncanny-learndash-groups' ) . '</h3>' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

		$required = apply_filters( 'ulgm_group_name_required', true );

		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
			$product_id = $cart_item['product_id'];
			$product    = wc_get_product( $product_id );
			if ( false === self::is_license_or_subscription_license( $product ) ) {
				continue;
			}

			$custom_buy = get_post_meta( $product_id, '_uo_custom_buy_product', true );

			if ( 'yes' === $custom_buy ) {
				$classes = array( 'ulgm-woo-group-settings form-row-wide form-uo-hidden' );
			} else {
				$classes = array( 'ulgm-woo-group-settings form-row-wide' );
			}
			// Value can be saved on settings page
			$per_seat_text = get_option( 'ulgm_per_seat_text', 'Seat' );

			woocommerce_form_field(
				'ulgm_group_name_' . $cart_item_key,
				apply_filters(
					'ulgm_group_name_args',
					array(
						'type'        => 'text',
						'class'       => $classes,
						'label'       => apply_filters( 'ulgm_group_name_text', sprintf( '%s: %s x %d %s(s)', __( 'Group Name for', 'uncanny-learndash-groups' ), $cart_item['data']->get_title(), $cart_item['quantity'], $per_seat_text ) ),
						'placeholder' => apply_filters( 'ulgm_group_name_placeholder', __( 'Enter group name', 'uncanny-learndash-groups' ) ),
						'required'    => $required,
						'default'     => $cart_item['ulgm_group_name'] ?? '',
						'description' => false === $required ? __( 'If left blank, the group name will be [First name] [Last name] - [Company name].', 'uncanny-learndash-groups' ) : __( 'Enter your group name.', 'uncanny-learndash-groups' ),
					)
				),
				$checkout->get_value( 'ulgm_group_name_' . $cart_item_key )
			);
		}

		echo '</div>';
	}


Scroll to Top