Created
October 26, 2017 14:19
-
-
Save vanbo/db7264db5ecf8dfade18db61f8b8bb40 to your computer and use it in GitHub Desktop.
WooCommerce: Save custom checkout field
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
| add_action( 'woocommerce_checkout_order_processed', 'prefix_save_field_on_checkout', 11, 2 ); | |
| function checkout_order_processed_add_referral_answer( $order_id, $posted ) { | |
| if ( ! isset( $_POST['checkout_field_name'] ) ) { | |
| return; | |
| } | |
| $order = wc_get_order( $order_id ); | |
| // WC < 3.0 | |
| update_post_meta( $order->id, 'order_meta_field_name', wc_clean( $_POST['checkout_field_name'] ) ); | |
| // WC > 3.0 | |
| $order->add_meta_data( 'order_meta_field_name', wc_clean( $_POST['checkout_field_name'] ), true ); | |
| $order->save(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment