Skip to content Skip to sidebar Skip to footer

Add A Line Break To Woocommerce Cart Item Names And Order Item Names

Context This question is a follow-up on the previous question titled Add a line break in Woocommerce Product Titles To me the code in this topic (seen here below) works like a cha

Solution 1:

To alter the product name display on cart items, minicart and order items (+ email notifications), use the following additional code:

// For mini cart and cart item name
add_action( 'woocommerce_cart_item_name', 'alter_wc_cart_item_name', 10, 2 );
function alter_wc_cart_item_name( $item_name, $cart_item ) {
    if ( strpos($item_name , '|') !== false ) {
        $item_name = str_replace( '|', '<br/>', $item_name );
    }
    return $item_name;
}

// For order item name (even on email notifications)
add_action( 'woocommerce_order_item_name', 'alter_wc_order_item_name', 10, 2 );
function alter_wc_order_item_name( $item_name, $item ) {
    if ( strpos($item_name , '|') !== false ) {
        $item_name = str_replace( '|', '<br/>', $item_name );
    }
    return $item_name;
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.


Post a Comment for "Add A Line Break To Woocommerce Cart Item Names And Order Item Names"