ulgm_group_name
Filters the group title before it is displayed, allowing modification of the group's name.
add_filter( 'ulgm_group_name', $callback, 10, 2 );
Description
Filters the group name for license subscriptions. Use this hook to dynamically alter or customize the displayed group name associated with a WooCommerce license subscription. It fires when the group title is being determined and can be useful for branding or custom organization.
Usage
add_filter( 'ulgm_group_name', 'your_function_name', 10, 2 );
Parameters
-
$group_title(mixed) - The `$group_title` parameter contains the current group title string that can be modified.
-
$order(mixed) - This parameter holds the current title or name of the group that is being processed.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the ulgm_group_name filter hook.
* This function modifies the group name for a license based on order details.
*
* @param mixed $group_title The current group title.
* @param mixed $order The WC_Order object associated with the license.
* @return string The modified group title.
*/
function my_custom_group_name_filter( $group_title, $order ) {
// If the group title is empty, let's try to create a more descriptive one.
if ( empty( trim( $group_title ) ) ) {
// Get customer name and company for a more personalized group name.
$customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$customer_company = $order->get_billing_company();
// Combine name and company, ensuring no double spaces.
$combined_name = trim( $customer_name . ' ' . $customer_company );
// If we have a combined name, use it as the group title.
if ( ! empty( $combined_name ) ) {
$group_title = $combined_name;
} else {
// As a last resort, if no customer name or company, use the order ID.
$group_title = 'Order #' . $order->get_id();
}
}
// Return the potentially modified group title.
return $group_title;
}
add_filter( 'ulgm_group_name', 'my_custom_group_name_filter', 10, 2 );
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-subscription.php:569
src/classes/woocommerce/woocommerce-license-subscription.php:814
src/classes/woocommerce/woocommerce-license-subscription.php:824
src/classes/woocommerce/woocommerce-license-subscription.php:837
src/classes/woocommerce/woocommerce-license.php:1478
src/classes/woocommerce/woocommerce-license.php:1856
// Fallback: check order meta when line item has no group name
if ( empty( trim( $group_title ) ) ) {
$group_title = $order->get_meta( SharedFunctions::$group_name_field, true );
}
if ( empty( trim( $group_title ) ) ) {
$group_title = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() . ' ' . $order->get_billing_company();
$group_title = apply_filters( 'ulgm_group_name', trim( $group_title ), $order );
}
if ( 'yes' === get_post_meta( $product_id, '_uo_custom_buy_product', true ) ) {
wp_update_post(
array(
'ID' => $product_id,
'post_author' => apply_filters( 'ulgm_custom_license_post_author', $user->ID, get_current_user_id(), 'license-purchase' ),
)