ulgm_group_name_args
Filters the arguments used to generate a group name, allowing modification before it's displayed.
add_filter( 'ulgm_group_name_args', $callback, 10, 1 );
Description
Filters the arguments used to generate the group name field on the WooCommerce checkout page. Developers can modify these arguments to customize the field's appearance, labels, or validation. This hook fires after license modification checks and before the group name field is rendered, allowing for dynamic adjustments.
Usage
add_filter( 'ulgm_group_name_args', 'your_function_name', 10, 1 );
Parameters
-
$classes(mixed) - This parameter contains a mixed value that is likely used to store or represent CSS classes associated with the group name field on the WooCommerce checkout page.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the arguments for the 'ulgm_group_name_args' hook.
* This example modifies the 'class' and 'label' arguments for the group name input field.
*/
add_filter( 'ulgm_group_name_args', function( $args, $cart_item_key, $cart_item ) {
// Add a custom class to the input field if it's for a subscription product.
if ( isset( $cart_item['variation'] ) && ! empty( $cart_item['variation']['subscription_id'] ) ) {
$args['class'][] = 'ulgm-woo-subscription-group-name';
}
// Modify the label to include a specific identifier for "Premium Group Licenses".
$args['label'] = sprintf(
__( 'Premium License Group Name (Item: %s)', 'my-custom-textdomain' ),
$cart_item['data']->get_title()
);
// Make the group name field mandatory for all license products added via this filter.
$args['required'] = true;
return $args;
}, 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:2061
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>';
}