• Hi,
    I have added the subtitle underneath my titles on category and single product pages with this

    function kia_add_subtitle_to_woocommerce(){
        if( function_exists( 'the_subtitle' ) ) the_subtitle( '<h4 class="subtitle">', '</h4>' );
    }
    add_action( 'woocommerce_single_product_summary', 'kia_add_subtitle_to_woocommerce', 7 ); 
    
    add_action( 'woocommerce_after_shop_loop_item_title', 'kia_add_subtitle_to_woocommerce', 7 );

    but I would also like to diplay it underneath the title on the cart page and in the mini cart. Is this possible?
    Thanks!

    https://www.ads-software.com/plugins/kia-subtitle/

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

    (@helgatheviking)

    Look in the cart.php template. You will see that the cart item title is run through the woocommerce_cart_item_name filter. Therefore, you could probably do something like the following:

    function kia_add_subtitle_to_woocommerce( $title, $cart_item ){
        if( function_exists( 'get_the_subtitle' ) && ( $subtitle = get_the_subtitle( $cart_item['product_id'] ) ) ) {
        	$title .= '<br/>' . $subtitle;
        }
    }
    add_filter( 'woocommerce_cart_item_name', 'kia_add_subtitle_to_woocommerce_cart', 10, 2 );

    NB: untested, so be wary of typos

    Thread Starter kanlbll

    (@kanlbll)

    hmm…did not work, I changed the function name because you forgot “cart” in the first line but I am still getting a blank screen.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    I told you it was untested. For the future, any time you get white screen of death you should use WP_DEBUG to find the cause.

    It looks like I named the function incorrectly (copy/paste fail) and forgot to return a value. With filters, you must always send a value back to the filter. This was just tested and working:

    function kia_add_subtitle_to_woocommerce_cart( $title, $cart_item ){
        if( function_exists( 'get_the_subtitle' ) && ( $subtitle = get_the_subtitle( $cart_item['product_id'] ) ) ) {
        	$title .= '<br/>' . $subtitle;
        }
        return $title;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding the subtitle underneath title in cart and minicart’ is closed to new replies.