Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active June 17, 2019 15:56
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 plugin-republic/4de94095fc3fa1f5375537d69271c731 to your computer and use it in GitHub Desktop.
Save plugin-republic/4de94095fc3fa1f5375537d69271c731 to your computer and use it in GitHub Desktop.
<?php
/**
* Add custom cart item data
*/
function plugin_republic_add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
if( isset( $_POST['pr-field'] ) ) {
$cart_item_data['pr_field'] = sanitize_text_field( $_POST['pr-field'] );
}
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'plugin_republic_add_cart_item_data', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment