Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created June 12, 2018 10:28
Show Gist options
  • Save plugin-republic/3a7397e725bf09d92ac5b31135102952 to your computer and use it in GitHub Desktop.
Save plugin-republic/3a7397e725bf09d92ac5b31135102952 to your computer and use it in GitHub Desktop.
/**
* Add the text field as item data to the cart object
* @since 1.0.0
* @param Array $cart_item_data Cart item meta data.
* @param Integer $product_id Product ID.
* @param Integer $variation_id Variation ID.
* @param Boolean $quantity Quantity
*/
function cfwc_add_custom_field_item_data( $cart_item_data, $product_id, $variation_id, $quantity ) {
if( ! empty( $_POST['cfwc-title-field'] ) ) {
// Add the item data
$cart_item_data['title_field'] = $_POST['cfwc-title-field'];
}
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'cfwc_add_custom_field_item_data', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment