ulgm_woocommerce_group_name_heading
Filters the HTML heading displayed for group names on the WooCommerce checkout page.
add_filter( 'ulgm_woocommerce_group_name_heading', $callback, 10, 1 );
Description
Filter the HTML heading for the Group Name field displayed on the WooCommerce checkout page. Developers can modify the heading content, add custom classes, or completely replace it to customize the checkout experience. This hook fires before the group name input field is rendered.
Usage
add_filter( 'ulgm_woocommerce_group_name_heading', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Filters the heading for the group name fields on the WooCommerce checkout page.
*
* This example demonstrates how to add a custom class to the heading's container
* and conditionally append additional text if a specific WooCommerce product is in the cart.
*
* @param string $heading_html The default HTML for the heading.
* @return string The modified HTML for the heading.
*/
add_filter( 'ulgm_woocommerce_group_name_heading', function( $heading_html ) {
// Assume we have a function to check if a specific product ID is in the cart.
// In a real scenario, this would involve WC()->cart->get_cart() and checking product IDs.
$specific_product_in_cart = false; // Replace with actual cart check logic
$target_product_id = 123; // Example product ID
if ( class_exists( 'WC_Cart' ) ) {
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( $cart_item['product_id'] === $target_product_id ) {
$specific_product_in_cart = true;
break;
}
}
}
// Add a custom class to the container div
$modified_heading_html = str_replace( '<div id="group_name_checkout_field">', '<div id="group_name_checkout_field" class="ulgm-custom-group-heading-container">', $heading_html );
// Conditionally append text if the specific product is in the cart
if ( $specific_product_in_cart ) {
$modified_heading_html .= '<span class="ulgm-important-note">(This group purchase requires special attention.)</span>';
}
return $modified_heading_html;
}, 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-license.php:2038
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>';
}