Created
November 9, 2023 07:28
-
-
Save kartikparmar/88467217105a49d460df7b3afd427524 to your computer and use it in GitHub Desktop.
Adding custom information in the cart item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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