add_filter( 'wpo_search_product_types', function ( $types ) {
$types[] = 'booking';
return $types;
}, 10, 1 );
add_filter('wpo_cart_item_is_price_readonly', function ($is_readonly, $cart_item_data) {
return isset($cart_item_data['booking']) ? true : $is_readonly;
}, 10, 2);
add_filter('wpo_cart_item_is_qty_readonly', function ($is_readonly, $cart_item_data) {
return isset($cart_item_data['booking']) ? true : $is_readonly;
}, 10, 2);
add_filter('wpo_update_cart_cart_item_meta', function ($cart_item_meta, $item) {
foreach ($_POST as $key => $value) {
if (preg_match('/^wc_bookings_field_(.*)/i', $key)) {
unset($_POST[$key]);
}
}
if (isset($_POST['add-to-cart'])) {
unset($_POST['add-to-cart']);
}
if ( isset($item['booking']) ) {
$persons = array();
if (isset($item['booking']['_persons'])) {
if (is_array($item['booking']['_persons'])) {
if (isset($item['booking']['_persons'][0])) {
$persons['wc_bookings_field_persons'] = $item['booking']['_persons'][0];
} else {
foreach ($item['booking']['_persons'] as $i => $v) {
$persons['wc_bookings_field_persons_' . $i] = $v;
}
}
} else {
$persons['wc_bookings_field_persons'] = $item['booking']['_persons'];
}
}
$_POST = array_merge($_POST, $persons, array(
'wc_bookings_field_start_date_month' => $item['booking']['_month'],
'wc_bookings_field_start_date_day' => $item['booking']['_day'],
'wc_bookings_field_start_date_year' => $item['booking']['_year'],
'wc_bookings_field_duration' => isset($item['booking']['_duration']) && $item['booking']['_duration'] > 0 ? $item['booking']['_duration'] : null,
'wc_bookings_field_resource' => isset($item['booking']['_resource_id']) ? $item['booking']['_resource_id'] : null,
'wc_bookings_field_start_date_time' => isset($item['booking']['_time']) && $item['booking']['_time'] !== '' ? date(\DateTime::ISO8601, strtotime("{$item['booking']['_year']}-{$item['booking']['_month']}-{$item['booking']['_day']} {$item['booking']['_time']}")) : null,
'wc_bookings_field_start_date_local_timezone' => isset($item['booking']['_local_timezone']) ? $item['booking']['_local_timezone'] : null,
'add-to-cart' => $item['product_id'],
));
if ( isset( $item['booking']['_booking_id'] ) ) {
wp_delete_post( $item['booking']['_booking_id'], true );
}
}
return array_merge($cart_item_meta, array(
'booking' => isset($item['booking']) ? $item['booking'] : null,
));
}, 10, 2);
add_filter('wpo_update_cart_loaded_product', function ($loaded_product, $item) {
return array_merge($loaded_product, array(
'booking' => isset($item['booking']) ? $item['booking'] : null,
'readonly_price' => isset($item['booking']) ? $item['data']->get_price() : null,
'readonly_custom_meta_fields_html' => isset($item['booking']) ? wc_get_formatted_cart_item_data($item) : '',
));
}, 10, 3);
add_filter('wpo_get_item_by_product', function ($product, $cart_item_data) {
return array_merge($product, array(
'booking' => isset($cart_item_data['booking']) ? $cart_item_data['booking'] : null,
));
}, 10, 2);WooCommerce Bookings, by WooCommerce Print
Created by: Alex Prokaev
Modified on: Mon, 10 Jun, 2019 at 1:11 PM
Did you find it helpful? Yes No
Send feedbackSorry we couldn't be helpful. Help us improve this article with your feedback.