ulgm_woocommerce_hide_course_title_in_product
Filters whether the course title should be hidden in the WooCommerce product details.
add_filter( 'ulgm_woocommerce_hide_course_title_in_product', $callback, 10, 1 );
Description
Filter to conditionally hide the course title within WooCommerce product listings, allowing customization of how course information is displayed alongside associated products. Developers can use this to control the visibility of course titles based on specific criteria or user roles, offering greater flexibility in product presentation.
Usage
add_filter( 'ulgm_woocommerce_hide_course_title_in_product', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter(
'ulgm_woocommerce_hide_course_title_in_product',
function ( $should_hide, $cart_item, $product_id ) {
// Example: Hide course titles for specific license products if they are already in the cart.
// This prevents duplicate display of course information if the user is adding a license
// for a course they already have access to via another product in their cart.
// Check if the $cart_item is valid and if it contains course information already
if ( $cart_item && isset( $cart_item['ulgm_courses'] ) && ! empty( $cart_item['ulgm_courses'] ) ) {
// If courses are already associated with this cart item, we might want to hide the title
// to avoid redundancy, especially if these are subscription products where course
// information is managed elsewhere.
return true; // Hide the course title
}
// You could add more complex logic here, for instance, checking if the product_id
// corresponds to a specific license type that should have its courses hidden.
// For example:
// $product = wc_get_product( $product_id );
// if ( $product && $product->get_meta( '_my_custom_license_type' ) === 'bundle' ) {
// return true;
// }
return $should_hide; // Return the original value if conditions are not met
},
10,
3 // The hook accepts 3 arguments: $should_hide, $cart_item, $product_id
);
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:1804
src/classes/woocommerce/woocommerce-license.php:1896
public function display_item_group_name( $cart_item_data, $cart_item ) {
if ( WoocommerceModifyGroup::is_modifying_license() ) {
return $cart_item_data;
}
if ( isset( $cart_item['ulgm_group_name'] ) && ! is_cart() ) {
$cart_item_data[] = array(
'name' => sprintf( __( '%s Name', 'uncanny-learndash-groups' ), LearnDash_Custom_Label::get_label( 'group' ) ),
'value' => isset( $cart_item['ulgm_group_name'] ) ? $cart_item['ulgm_group_name'] : '',
);
}
$product_id = $cart_item['product_id'];
$product = wc_get_product( $product_id );
if ( ! ( $product instanceof WC_Product ) ) {
return $cart_item_data;
}
if ( 'license' !== $product->get_type() ) {
return $cart_item_data;
}
//if ( isset( $cart_item['ulgm_courses'] ) && ! empty( $cart_item['ulgm_courses'] ) ) {
if (
true === apply_filters( 'ulgm_woocommerce_hide_course_title_in_product', false, null, null ) ||
true === apply_filters( 'ulgm_woocommerce_hide_course_title_in_subscription', false, '', null, null )
) {
return $cart_item_data;
}
$courses = self::fetch_courses_from_license( $product, false, true );
$value = '';
if ( ! empty( $courses ) && is_array( $courses ) ) {
$value = join( ', ', $courses );
}
$cart_item_data[] = array(
'name' => LearnDash_Custom_Label::get_label( 'courses' ),
'value' => empty( $cart_item['ulgm_courses'] ) ? $value : $cart_item['ulgm_courses'],
);
//}
return $cart_item_data;
}