ulgm_license_product_thumbnail_in_cart
Filters the product thumbnail displayed in the cart to optionally show the license thumbnail.
add_filter( 'ulgm_license_product_thumbnail_in_cart', $callback, 10, 2 );
Description
This filter allows developers to modify the product thumbnail displayed for license products in the WooCommerce cart. By default, it returns false, effectively removing the thumbnail. Developers can return an image URL, an HTML image tag, or any other markup to customize the cart item display for license products.
Usage
add_filter( 'ulgm_license_product_thumbnail_in_cart', 'your_function_name', 10, 2 );
Parameters
-
$product_get_image(mixed) - This parameter is a boolean that controls whether to display the default WooCommerce product thumbnail or not.
-
$product(mixed) - This parameter holds the product object obtained from the cart item, allowing for checks on its type and properties.
Return Value
The filtered value.
Examples
// Example of how to use the ulgm_license_product_thumbnail_in_cart filter hook.
// This example will remove the thumbnail for license products in the cart
// if the license product's ID is greater than 100.
function my_custom_license_product_thumbnail_in_cart( $original_thumbnail_html, $product_get_image, $product ) {
// Check if the product is a license type (already handled by the hook's context, but good practice)
if ( $product instanceof WC_Product && $product->is_type( 'license' ) ) {
// Get the product ID
$product_id = $product->get_id();
// If the product ID is greater than 100, return an empty string to remove the thumbnail.
if ( $product_id > 100 ) {
return ''; // Remove the thumbnail
}
}
// Otherwise, return the original thumbnail HTML or the modified one if needed.
return $product_get_image;
}
add_filter( 'ulgm_license_product_thumbnail_in_cart', 'my_custom_license_product_thumbnail_in_cart', 10, 3 );
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:608
public function woocommerce_cart_item_thumbnail_func( $product_get_image, $cart_item, $cart_item_key ) {
if ( ! empty( $cart_item ) ) {
$product = $cart_item['data'];
if ( $product instanceof WC_Product && $product->is_type( 'license' ) ) {
return apply_filters( 'ulgm_license_product_thumbnail_in_cart', false, $product_get_image, $product );
}
}
return $product_get_image;
}