• Resolved armedandgorgeous

    (@armedandgorgeous)


    Hi,
    When someone adds a product and views it in the cart it currently displays the name the quantity and the price. I am on woocommerce

    I also want to have a little tick or bullet point underneath this data that says ” this is eligible for free shipping” and “90 day returns”

    would someone be kind enough to provide some code that would do this or at the very least point me in the direction of where I need to be?

    THank you

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @armedandgorgeous

    I understand that you want to add a custom message on the cart page when a product is added to the cart.

    The following articles should help you achieve that:

    https://kyraweb.ca/adding-custom-message-on-cart-page-woocommerce/
    https://www.scratchcode.io/how-to-add-custom-text-on-cart-page-in-woocommerce/

    The snippet from this thread may also work for you:

    https://www.ads-software.com/support/topic/adding-custom-text-to-the-cart-and-checkout/

    There is also a plugin Add Free shipping text For WooCommerce Cart which you can use: https://www.ads-software.com/plugins/add-free-shipping-text-on-cart-page/

    I hope this helps!

    Thread Starter armedandgorgeous

    (@armedandgorgeous)

    Hi thanks for the response, but I don’t want to add it to the cart page per se, I want to add it to the product metadata that’s displayed underneath it.

    for reference this website does exactly what I want to achieve: https://beddingenvy.co.uk/cart

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @armedandgorgeous.

    Thanks for sending us your example.

    OK, so I assume the specific data will be different from product to product — some products would (as example) say “free shipping included” while some won’t.

    In order to achieve that, you would need to

    a) add the necessary custom fields to the actual product data
    b) add the product data to the cart item
    c) show the data in the cart

    That also means if you are going the code-route, you would need to do this individually for each product, or add multiple product IDs in array.

    You can see a great example of how to do that here:

    https://iconicwp.com/blog/add-custom-cart-item-data-woocommerce/
    https://wisdmlabs.com/blog/add-custom-data-woocommerce-order/

    Cheers!

    Thread Starter armedandgorgeous

    (@armedandgorgeous)

    HI thanks for the reply. I’m in the process of piecing this together. I’m new to coding why would this not work? Thanks

    add_filter( 'woocommerce_cart_item_name', 'custom_text_cart_item_name', 10, 3 );
    function custom_text_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
    	global $woocommerce;
    	
    	
    	$price = $woocommerce->cart->get_cart_total();	
    	$product_id = $product->get_id();
    
    	if ( 47 > $price ) {
    		$item_name .= '<br /><div >' . __("This item has free delivery", "woocommerce") . '</div>';
    	}
    
           if ( has_term( 'jewellery', 'product_cat', $product_id ) ) { 
    	        $item_name .= '<br /><div >' . __("Enjoy 90 day no quibble returns", "woocommerce") . '</div>';
    	}
    	
    	return $item_name;
    }

    I can get that function to add text below the title, but as soon as I add my conditions it doesn’t work. I don’t think my variables are fetching the data I require but this is how I imagine it working.

    Thanks!

    Thread Starter armedandgorgeous

    (@armedandgorgeous)

    Okay so ive managed to get it pretty much sorted. My issue with was my greater than sign was the wrong way round! Anyway, my last issue is that if I have jewellery in my basket then it adds “90 day returns” on all items. Some items will most certainly not be 90 day returns so I need to make this not apply to all items.

    add_filter( 'woocommerce_cart_item_name', 'custom_text_cart_item_name', 10, 3 );
    function custom_text_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
    	global $woocommerce;
    	
    	foreach( WC()->cart->get_cart() as $cart_item ){
        $product_id = $cart_item['product_id'];
    }
    	
    	$amount = $woocommerce->cart->cart_contents_total;
    
    	if ( 47 < $amount ) {
    		$item_name .= '<br /><div >' . __("-Free delivery for this item!", "woocommerce") . '</div>';
    	}
    
    	
    
    	
    	foreach( WC()->cart->get_cart() as $cart_item ){
        // For product categories (term IDs, term slugs or term names)
        if( has_term( array('jewellery'), 'product_cat', $cart_item['product_id'] ) ) {
    		$item_name .= '<br /><div >' . __("-90 day returns", "woocommerce") . '</div>';
    	}
    	}
    
    	
    
    	
    	
    	return $item_name;
    }
    Thread Starter armedandgorgeous

    (@armedandgorgeous)

    add_filter( ‘woocommerce_cart_item_name’, ‘custom_text_cart_item_name’, 10, 3 );
    function custom_text_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
    global $woocommerce;

    foreach( WC()->cart->get_cart() as $cart_item ){
    $product_id = $cart_item[‘product_id’];
    }

    $amount = $woocommerce->cart->cart_contents_total;

    if ( 47 < $amount ) {
    $item_name .= ‘<br /><div >’ . __(“-Free delivery for this item!”, “woocommerce”) . ‘</div>’;
    }

    return $item_name;

    }

    add_filter( ‘woocommerce_cart_item_name’, ‘custom_text_cart_item_name2’, 10, 3 );
    function custom_text_cart_item_name2( $item_name, $cart_item, $cart_item_key ) {
    global $woocommerce;

    $product_id = $cart_item[‘product_id’];

    if( has_term( array(‘jewellery’), ‘product_cat’, $cart_item[‘product_id’] ) ) {
    return $item_name.”- 90 day no quibble returns” . ‘<br>’;

    }

    else {
    return $item_name;
    }

    }

    For anyone reading this thread I’ve managed to get it to do what I want it to do with this code!

    Hi @armedandgorgeous!

    Fantastic! I am happy to hear that you figured it out, and thank you for sharing it with the community!

    I’m going to mark this as resolved, but feel free to reach out to us again, creating a new topic, if you need anything else!

    My very best,

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add text under product in the cart’ is closed to new replies.