Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created November 9, 2023 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kartikparmar/88467217105a49d460df7b3afd427524 to your computer and use it in GitHub Desktop.
Save kartikparmar/88467217105a49d460df7b3afd427524 to your computer and use it in GitHub Desktop.
Adding custom information in the cart item
<?php
/* Adding the custom infromation in the cart item */
function add_custom_info_to_cart_item( $cart_item_meta, $product_id ) {
$cart_item_meta['custom_information'] = 'This is my <strong>custom</strong> information.<br> Please contact support for more information';
return $cart_item_meta;
}
add_filter( 'woocommerce_add_cart_item_data', 'add_custom_info_to_cart_item', 25, 2 );
/* Displaying the custom infroamtion in the cart table */
function show_custom_info_to_cart_item( $other_data, $cart_item ) {
if ( isset( $cart_item['custom_information'] ) ) {
$other_data[] = array(
'name' => __( 'My Custom Information', 'domain' ),
'display' => $cart_item['custom_information'],
);
}
return $other_data;
}
add_filter( 'woocommerce_get_item_data', 'show_custom_info_to_cart_item', 25, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment