Last active
November 11, 2017 11:05
-
-
Save bhavik-kiri/06a4d1cb27d0a32619f5a64677371e33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Add data to cart item | |
*/ | |
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 25, 2 ); | |
function add_cart_item_data( $cart_item_meta, $product_id ) { | |
if ( isset( $_POST ['customer_name'] ) && isset( $_POST ['customer_message'] ) ) { | |
$custom_data = array() ; | |
$custom_data [ 'customer_name' ] = isset( $_POST ['customer_name'] ) ? sanitize_text_field ( $_POST ['customer_name'] ) : "" ; | |
$custom_data [ 'customer_message' ] = isset( $_POST ['customer_message'] ) ? sanitize_text_field ( $_POST ['customer_message'] ): "" ; | |
$cart_item_meta ['custom_data'] = $custom_data ; | |
} | |
return $cart_item_meta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment