Hi @fredointhecut,
Thanks for sending me the parts of your installation. I was now able to reproduce the issue and produce a quick fix for this. Here’s how you can implement it:
- Copy the code below or get it from my GitLab Snippet and paste it into your active theme’s
functions.php
.
- Go to Settings → Secondary Title and switch
Only show in main post
to Off
as shown in this screenshot.
After that, the secondary title will be displayed in your cart and on the checkout page. Make sure Secondary Title is active and the product actually has a secondary title; otherwise, it’ll fall back to showing the default title.
/**
* This filter hook modifies the name of the item in the WooCommerce cart.
* It checks if the plugin Secondary Title is active and if the product ID is set.
* If the secondary title is not set or is empty, it uses the original formatted string.
*
* @hooked woocommerce_cart_item_name - 10
*
* @param string $formatted_string The original name of the item in the cart.
* @param array $cart_item An array containing the cart item's data.
*
* @return string The modified name of the item in the cart.
*
* @since 2024-06-12
* @author Kolja Nolte <[email protected]>
*/
add_filter('woocommerce_cart_item_name', function (string $formatted_string, array $cart_item): string {
// Check if the Secondary Title plugin is active and the product ID is set.
// If not, return the original formatted string.
if (!defined('SECONDARY_TITLE_VERSION') && isset($cart_item['product_id'])) {
return $formatted_string;
}
// Get the secondary title for the product.
$secondary_title = (string)get_secondary_title($cart_item['product_id']);
// If the secondary title is set, use it as the item name.
// Otherwise, use the original formatted string.
$formatted_string = $secondary_title ?: $formatted_string;
return (string)$formatted_string;
}, 10, 2);
Let me know if that worked for you.