Skip to content

Instantly share code, notes, and snippets.

@rcstr
Last active August 8, 2019 14:19
Show Gist options
  • Save rcstr/f72c8dff0faa0910068b813b509b6d77 to your computer and use it in GitHub Desktop.
Save rcstr/f72c8dff0faa0910068b813b509b6d77 to your computer and use it in GitHub Desktop.
<?php
function cstr_add_cart_item_data( $cart_item_data, $product_id ) {
if ( isset( $_POST ) && ! empty( $product_id ) ) {
$post_data = $_POST;
} else {
return;
}
if ( empty( $cart_item_data['my_field'] ) ) {
$cart_item_data['my_field'] = array();
}
// add my data.
return $cart_item_data;
}
// Add item data to the cart.
add_filter( 'woocommerce_add_cart_item_data', 'cstr_add_cart_item_data', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment