Last active
September 15, 2022 08:00
-
-
Save kartikparmar/9e47a9b43912c69cdd425a674ee7d016 to your computer and use it in GitHub Desktop.
Adding custom item data to order when order is placed for the bookable product.
This file contains 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
<?php | |
/** | |
* Adding custom data to item when booking order is placed. | |
* | |
* @param int $item_id Item ID. | |
* @param int $product_id Product ID. | |
* @param array $booking_data Booking data. | |
*/ | |
function bkap_update_item_meta( $item_id, $product_id, $booking_data ) { | |
$order_id = wc_get_order_id_by_order_item_id( $item_id ); | |
// Start Date. | |
$date_booking = bkap_date_as_format( $booking_data['hidden_date'], 'm-d-Y' ); | |
wc_add_order_item_meta( $item_id, 'Custom_Field_1', sanitize_text_field( $date_booking, true ) ); | |
update_post_meta( $order_id, 'Custom_Field_1', sanitize_text_field( sanitize_text_field( $date_booking, true ) ) ); | |
// End Date. | |
$date_booking = bkap_date_as_format( $booking_data['hidden_date_checkout'], 'm-d-Y' ); | |
wc_add_order_item_meta( $item_id, 'Custom_Field_2', sanitize_text_field( $date_booking, true ) ); | |
update_post_meta( $order_id, 'Custom_Field_2', sanitize_text_field( sanitize_text_field( $date_booking, true ) ) ); | |
} | |
add_action( 'bkap_update_item_meta', 'bkap_update_item_meta', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment