ulgm_woocommerce_hide_course_title_in_subscription
Filters whether to hide the course title in the WooCommerce subscription details.
add_filter( 'ulgm_woocommerce_hide_course_title_in_subscription', $callback, 10, 3 );
Description
This filter allows developers to conditionally hide the course title from WooCommerce subscription products. Return `true` to hide the title. This hook fires when preparing the product title for display in WooCommerce subscriptions, enabling fine-grained control over what information is presented to users.
Usage
add_filter( 'ulgm_woocommerce_hide_course_title_in_subscription', 'your_function_name', 10, 3 );
Parameters
-
$title(mixed) - This parameter is a boolean value that, when set to `true`, indicates that the course title should be hidden.
-
$cart_item(mixed) - This parameter holds the current product title of the cart item.
-
$cart_item_key(mixed) - This parameter contains the cart item data, which is used to determine if a course title should be hidden.
Return Value
The filtered value.
Examples
/**
* Filter to potentially hide the course title in WooCommerce subscription cart items.
*
* This function allows developers to conditionally prevent the course title from
* being displayed alongside the product title in WooCommerce subscription cart items.
* By default, it does not hide the course title.
*
* @param bool $hide_course_title Whether to hide the course title. Defaults to false.
* @param mixed $title The current product title.
* @param array $cart_item The current cart item data.
* @param string $cart_item_key The unique key for the cart item.
*
* @return bool Whether the course title should be hidden.
*/
function my_plugin_hide_course_title_in_subscription( $hide_course_title, $title, $cart_item, $cart_item_key ) {
// Example: Only hide the course title if the product is a specific type,
// for instance, if it's a membership product and not a standalone course.
if ( isset( $cart_item['variation'] ) && ! empty( $cart_item['variation'] ) ) {
// This is a simplified example. In a real scenario, you'd check for
// specific variation attributes or product types.
$product_id = $cart_item['product_id'];
$product = wc_get_product( $product_id );
// If this is a subscription for a membership plan, hide the course title.
// This assumes you have a way to identify membership products.
// Replace 'is_membership_product' with your actual function or check.
if ( $product && $product->is_type( 'variable-subscription' ) && ! function_exists( 'is_membership_product' ) || ( function_exists( 'is_membership_product' ) && is_membership_product( $product_id ) ) ) {
return true; // Hide the course title
}
}
// Otherwise, return the default value (don't hide).
return $hide_course_title;
}
add_filter( 'ulgm_woocommerce_hide_course_title_in_subscription', 'my_plugin_hide_course_title_in_subscription', 10, 4 );
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:224
src/classes/woocommerce/woocommerce-license.php:1805
src/classes/woocommerce/woocommerce-license.php:1897
public function add_course_name_in_product_title( $title, $cart_item, $cart_item_key ) {
if ( empty( $cart_item ) ) {
return $title;
}
if ( true === apply_filters( 'ulgm_woocommerce_hide_course_title_in_subscription', false, $title, $cart_item, $cart_item_key ) ) {
return $title;
}
// hide when checkout
if ( is_checkout() ) {
return $title;
}
if ( ! class_exists( 'WC_Subscriptions_Product' ) ) {
return $title;
}
$product = $cart_item['data'];
if ( ! WC_Subscriptions_Product::is_subscription( $product->get_id() ) ) {
return $title;
}
return $title . WoocommerceLicense::fetch_courses_from_license( $product );
}