ulgm_woocommerce_hide_group_name_fields
Filters whether WooCommerce group name fields should be hidden for the user.
add_filter( 'ulgm_woocommerce_hide_group_name_fields', $callback, 10, 1 );
Description
Use this filter to programmatically control whether group name fields are hidden during WooCommerce checkout. By default, the filter returns false. You can return true to force the hiding of these fields, overriding other settings. This hook fires early in the checkout process before fields are displayed.
Usage
add_filter( 'ulgm_woocommerce_hide_group_name_fields', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to hook into 'ulgm_woocommerce_hide_group_name_fields' to conditionally hide group name fields.
*
* This filter allows developers to programmatically decide whether to hide the "Group Name" fields
* on the WooCommerce checkout page, beyond the default plugin settings.
*
* @param bool $hide_fields Whether to hide the group name fields. Default is false.
* @return bool True if the fields should be hidden, false otherwise.
*/
add_filter( 'ulgm_woocommerce_hide_group_name_fields', 'my_custom_hide_group_name_fields_logic', 10, 1 );
function my_custom_hide_group_name_fields_logic( $hide_fields ) {
// Example: Hide group name fields if a specific product is in the cart.
// Replace '123' with the actual product ID you want to check for.
$product_id_to_check = 123;
// Check if the product with the specified ID is in the cart.
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( $cart_item['product_id'] === $product_id_to_check ) {
// If the product is found, return true to hide the group name fields.
return true;
}
}
// If the specific product is not found, return the original value of $hide_fields.
// This ensures that other filters or the default behavior are respected.
return $hide_fields;
}
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:2013
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>';
}