Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    You can modify the product name in the cart via the woocommerce_cart_item_name filter.

    Untested:

    function kia_subtitle_in_cart( $title, $cart_item, $cart_item_key ){
    	$product_id   = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
    
    	if( function_exists( 'get_the_subtitle' ) && $subtitle = get_the_subtitle( $product_id ) ){
    		$title. = ' | ' . $subtitle;
    	}
    	return $title;
    }
    add_filter( 'woocommerce_cart_item_name', 'kia_subtitle_in_cart', 10, 3 );
    Thread Starter NejcZ

    (@nejcz)

    Direct copy&paste wont work (page loads blank). I have added subtitles manualy in other files, but can’t get it to work in cart.

    What about alternative functions to add subtitles in all woocoomerce functions? If anyone has ever asked about that..

    Thanks for your support 🙂

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Direct copy&paste wont work (page loads blank).

    As I said, it was untested. But a blank page would indicate some kind of error, if you enable DEBUG_MODE then you can probably track down the error and hopefully resolve it.

    See: http://codex.wordpress.org/Debugging_in_WordPress

    Just a minor error:

    function kia_subtitle_in_cart( $title, $cart_item, $cart_item_key ){
    	$product_id   = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
    
    	if( function_exists( 'get_the_subtitle' ) && $subtitle = get_the_subtitle( $product_id ) ){
    		$title .= ' | ' . $subtitle;
    	}
    	return $title;
    }
    add_filter( 'woocommerce_cart_item_name', 'kia_subtitle_in_cart', 10, 3 );

    OR this seems like it should add the subtitle everywhere, but I don’t really have time to check:

    function kia_subtitle_for_woocommerce_products( $title, $product ){
    
    	if( function_exists( 'get_the_subtitle' ) && $subtitle = get_the_subtitle( $product->id ) ){
    		$title .= ' | ' . $subtitle;
    	}
    	return $title;
    }
    add_filter( 'woocommerce_product_title', 'kia_subtitle_for_woocommerce_products', 10, 2 );
    Thread Starter NejcZ

    (@nejcz)

    Thank you very much for your support! Both solutions seems to be forking just fine!

    Hello,
    I finally got my subtitle on the Cart thanks to your code.

    Is there a way to bring the Subtitle below the Title?
    Right now it’s displaying: Title | Subtitle

    I tried using a
    and that worked…but, while
    is invisible in cart, its visible in other parts of the site. That’s no good…

    Is there another way to bring Subtitle to the next line?

    Title
    Subtitle

    Thank you!

    Plugin Author HelgaTheViking

    (@helgatheviking)

    If you wrap the $subtitle in a <span> or <div> element then you can style is directly with CSS, including using display: block to bump it to the next line.

    Hello Helga!
    Thank your for your quick response. You’re awesome. Got it working after 12 trial and errors 🙂 [Must…learn….php!]

    The subtitle dropped to the next line without any styling in the css. Tried to style through stylesheet, but no effect. Is there any reason it should not work using “.subtitlecart {color:blue;font-size:30;} ?

    Also tried to insert style directly into the function.php along the lines…
    ….$title .= ‘<div class=”color:blue;font-size:20px;”></div>’ . $subtitle;
    No effect.

    Grateful for anyone’s help.

    Here is what I ended up using to get it to work thus far. Might be of help to others…

    ————————————————–
    function kia_subtitle_for_woocommerce_products( $title, $product ){

    if( function_exists( ‘get_the_subtitle’ ) && $subtitle = get_the_subtitle( $product->id ) ){
    $title .= ‘<div class=”subtitlecart”></div>‘ . $subtitle;
    }
    return $title;
    }
    add_filter( ‘woocommerce_product_title’, ‘kia_subtitle_for_woocommerce_products’, 10, 4 );

    Plugin Author HelgaTheViking

    (@helgatheviking)

    You haven’t wrapped the <div> around the $subtitle, hence you are getting an empty div.

    function kia_subtitle_for_woocommerce_products( $title, $product ){
    
    	if( function_exists( 'get_the_subtitle' ) && $subtitle = get_the_subtitle( $product->id ) ){
    		$title .= '<div class="subtitle">' . $subtitle . '</div>';
    	}
    	return $title;
    }
    add_filter( 'woocommerce_product_title', 'kia_subtitle_for_woocommerce_products', 10, 2 );

    Worked Perfectly. Genius!
    Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Subtitle in woocoomerce cart and mini-cart’ is closed to new replies.