• Resolved fredointhecut

    (@fredointhecut)


    Hey, im using the plugin because my product names are imported and clients dont need to see all the information that is in them. So this works perfect for me in carousels, shop page, product view etc. but if i go to cart or checkout page it shows the real name not the secondary one. Is it possible to show the secondary name all the time?

    Thanks,
    Fredi

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author thaikolja

    (@thaikolja)

    Hi @fredointhecut,

    Thanks for reaching out.

    I wish I could give you a simple code snippet or step-by-step guide on how to do that, but, as in so many other cases, WP sites are often heavily customized.

    That kind of makes it close to impossible for me give you directions this fast, because in order to solve this issue, I need to be able to reproduce it.

    Is there any way that you feel comfortable with where you could share parts of your website with me? Maybe even the theme (+ child theme, if it exists) would be enough to mirror your website and come up with the solution, the chances here are 50/50.

    I’d love to help you out on this one but I need to be able to reproduce the issue. Do you maybe have a private/secured staging environment for your current site? BTW: I assume you’re using WooCommerce, is that right?

    Cheers,

    Kolja

    Thread Starter fredointhecut

    (@fredointhecut)

    Hey,

    Awesome how fast answer time, appreciate!

    Yes i do have dev version of the page, made two “TEST” products so you can see them easily.

    https://dev-surgitech.pantheonsite.io/

    shop page is just /shop if you need to see that one also.

    I used underscores for theme, not very heavy modifications going on there in my opinion, trying to keep it clean. If you have any more questions then im here to answer, thank you again for fast answer!

    Fredi

    Plugin Author thaikolja

    (@thaikolja)

    Perfect — almost lol. Can you share the login details also so that I can make a copy of the site and fix it locally (if you’re okay with that)? It’ll be much easier to test changes and make sure nothing else breaks in the process.

    If you’re cool with that, you can send it to [email protected] and encrypt it with PGP to be safe. Here’s my public key.

    Plugin Author thaikolja

    (@thaikolja)

    Sorry for the push, but did you receive my latest comment?

    Plugin Author thaikolja

    (@thaikolja)

    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:

    1. Copy the code below or get it from my GitLab Snippet and paste it into your active theme’s functions.php.
    2. Go to SettingsSecondary 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.

    Thread Starter fredointhecut

    (@fredointhecut)

    Hey @thaikolja,

    This solution worked perfect for me, now it shows secondary name in checkout and cart pages also.
    I apprecieate your time and always fast responses, thanks you’re awesome!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.