Subtitle in woocoomerce cart and mini-cart
-
Is there a way to add subtitle to Woocoomerce cart page and mini cart widget? Thanks.
-
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 );
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 🙂
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 );
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 | SubtitleI 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
SubtitleThank you!
If you wrap the
$subtitle
in a<span>
or<div>
element then you can style is directly with CSS, including usingdisplay: 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 );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!
- The topic ‘Subtitle in woocoomerce cart and mini-cart’ is closed to new replies.