ulgm_hide_group_name_field_on_product_page
Filters the visibility of the group name field on the product page.
add_filter( 'ulgm_hide_group_name_field_on_product_page', $callback, 10, 1 );
Description
Filters whether to hide the group name field on the WooCommerce product page. Developers can return `true` to force the field to be hidden, overriding other plugin settings. This hook fires after initial checks for license modification and before checking plugin options.
Usage
add_filter( 'ulgm_hide_group_name_field_on_product_page', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
// Example of how to use the 'ulgm_hide_group_name_field_on_product_page' filter.
// This code would typically be placed in your theme's functions.php file or a custom plugin.
add_filter( 'ulgm_hide_group_name_field_on_product_page', 'my_custom_hide_group_name_field', 10, 1 );
/**
* Conditionally hides the group name field on specific product pages.
*
* @param bool $hide_field Whether to hide the group name field. Default is false.
* @return bool True to hide the field, false otherwise.
*/
function my_custom_hide_group_name_field( $hide_field ) {
// Check if we are on a specific product page that should hide the field.
// For example, let's say we want to hide it for products with ID 123 or 456.
global $product;
// Ensure we have a product object to check against.
if ( ! $product instanceof WC_Product ) {
return $hide_field; // Return the default value if not on a product page.
}
$product_id = $product->get_id();
if ( in_array( $product_id, array( 123, 456 ) ) ) {
// Hide the group name field for product IDs 123 and 456.
return true;
}
// If it's not one of the specific product IDs, return the original value
// (which is false by default, meaning show the field).
return $hide_field;
}
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:1922
public function add_group_name_field() {
if ( WoocommerceModifyGroup::is_modifying_license() ) {
return;
}
if ( apply_filters( 'ulgm_hide_group_name_field_on_product_page', false ) ) {
return;
}
if ( 'yes' === get_option( 'ulgm_hide_group_name_fields_on_product_page', 'no' ) ) {
return;
}
global $product;
if ( false === self::is_license_or_subscription_license( $product ) ) {
return;
}
echo '<div class="group-name-field">';
echo '<label for="ulgm_group_name">' . apply_filters( 'ulgm_group_name_text', esc_attr__( 'Group Name', 'uncanny-learndash-groups' ) ) . '</label>';
echo '<input type="text" id="ulgm_group_name" name="ulgm_group_name" />';
echo '</div>';
}