Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allows syncing the booking date from multiple FooEvents Bookings products to multiple fields in your CRM
<?php
function wpf_bookable_products_meta_fields( $fields ) {
$args = array(
'post_type' => 'product',
'nopaging' => true,
'meta_key' => 'WooCommerceEventsType',
'meta_value' => 'bookings',
);
$products = get_posts( $args );
foreach ( $products as $product ) {
$fields[ 'booking_date_' . $product->ID ] = array(
'label' => 'Bookings Date - ' . $product->post_title,
'type' => 'date',
'group' => 'woocommerce_order',
);
}
return $fields;
}
add_filter( 'wpf_meta_fields', 'wpf_bookable_products_meta_fields' );
function sync_booking_dates( $update_data, $attendee, $order_id ) {
$product_id = $attendee['WooCommerceEventsProductID'];
$update_data[ 'booking_date_' . $product_id ] = get_post_meta( $product_id, 'WooCommerceEventsDate', true );
return $update_data;
}
add_action( 'wpf_woocommerce_attendee_data', 'sync_booking_dates', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment