Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugin-republic/f3e786b7f387a1210c0ab43ee7e2d0a8 to your computer and use it in GitHub Desktop.
Save plugin-republic/f3e786b7f387a1210c0ab43ee7e2d0a8 to your computer and use it in GitHub Desktop.
<?php
/**
* Add custom meta to order
*/
function plugin_republic_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
if( isset( $values['pr_field'] ) ) {
$item->add_meta_data(
__( 'Your name', 'plugin-republic' ),
$values['pr_field'],
true
);
}
}
add_action( 'woocommerce_checkout_create_order_line_item', 'plugin_republic_checkout_create_order_line_item', 10, 4 );
@mohammadYousefiDev
Copy link

order item meta saves in wp_woocommerce_order_itemmeta table
and gets with $order->get_items(); method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment