Created
December 27, 2023 10:57
-
-
Save kartikparmar/6c8aed4863835447042f37e4c4e1f697 to your computer and use it in GitHub Desktop.
Adding fees, delivery and address information to view bookings page, csv, print
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
<?php | |
/* Adding Column on View Bookings */ | |
function bkap_view_booking_columns( $columns ) { | |
$additional_columns = array( 'bkap_invoice' => __( 'Invoice', 'woocommerce-booking' ), 'bkap_delivery' => __( 'Delivery', 'woocommerce-booking' ), 'bkap_customer_address' => __( 'Customer Address', 'woocommerce-booking' ) ); | |
// Adding column after Booked by hence 5. | |
$columns = array_slice( $columns, 0, 5, true ) + $additional_columns + array_slice( $columns, 5, count( $columns ) - 5, true ); | |
return $columns; | |
} | |
add_filter( 'bkap_view_booking_columns', 'bkap_view_booking_columns', 10, 1 ); | |
/* Adding Booking Data on View Bookings page */ | |
function bkap_view_booking_columns_data( $column ) { | |
global $post; | |
if ( get_post_type( $post->ID ) === 'bkap_booking' ) { | |
$booking = new BKAP_Booking( $post->ID ); | |
switch ( $column ) { | |
case 'bkap_invoice': | |
$order_id = $booking->order_id; | |
$fees_string = ''; | |
$order = wc_get_order($order_id); | |
if ( $order ) { | |
$fees = $order->get_fees(); | |
// Initialize an array to store fees information | |
$fees_info = array(); | |
// Loop through each fee | |
foreach ($fees as $fee) { | |
// Get fee name and amount | |
$fee_name = $fee->get_name(); | |
$fee_amount = $fee->get_total(); | |
// Add fee information to the array | |
$fees_info[] = "$fee_name: $fee_amount"; | |
} | |
// Combine fees information into a single string | |
$fees_string = implode('| ', $fees_info); | |
} | |
echo $fees_string; | |
break; | |
case 'bkap_delivery': | |
$order_id = $booking->order_id; | |
$shipping_string = ''; | |
$order = wc_get_order($order_id); | |
if ( $order ) { | |
// Get the shipping methods | |
$shipping_methods = $order->get_shipping_methods(); | |
// Initialize an array to store shipping information | |
$shipping_info = array(); | |
// Loop through each shipping method | |
foreach ($shipping_methods as $shipping_method) { | |
// Get shipping method name and amount | |
$shipping_name = $shipping_method->get_name(); | |
$shipping_amount = $shipping_method->get_total(); | |
// Add shipping information to the array | |
$shipping_info[] = "$shipping_name: $shipping_amount"; | |
} | |
// Combine shipping information into a single string | |
$shipping_string = implode('| ', $shipping_info); | |
} | |
// Output the shipping string | |
echo $shipping_string; | |
break; | |
case 'bkap_customer_address': | |
$order = $booking->get_order(); | |
$customer_address = ''; | |
if ( $order ) { | |
$billing_address_1 = $order->get_billing_address_1(); | |
$billing_address_2 = $order->get_billing_address_2(); | |
$customer_address = $billing_address_1 . ' ' . $billing_address_2; | |
} | |
echo $customer_address; | |
} | |
} | |
} | |
add_action( 'manage_bkap_booking_posts_custom_column', 'bkap_view_booking_columns_data', 2 ); | |
/* Adding column to CSV and Print */ | |
function bkap_bookings_csv_columns( $columns ) { | |
$additional_columns = array( 'bkap_invoice' => __( 'Invoice', 'woocommerce-booking' ), 'bkap_delivery' => __( 'Delivery', 'woocommerce-booking' ), 'bkap_customer_address' => __( 'Customer Address', 'woocommerce-booking' ) ); | |
// Adding column after Booked by hence 4. | |
$columns = array_slice( $columns, 0, 4, true ) + $additional_columns + array_slice( $columns, 4, count( $columns ) - 4, true ); | |
return $columns; | |
} | |
add_filter( 'bkap_bookings_csv_columns', 'bkap_bookings_csv_columns', 10, 1 ); | |
/* Adding Booking Data to CSV */ | |
function bkap_bookings_csv_individual_data( $row, $booking, $booking_id, $data ) { | |
extract( $data ); | |
// Fetching Custom Email. | |
$customer = $booking->get_customer(); | |
$customer_email = $customer->email; | |
$invoice = ''; | |
$delivery = ''; | |
// Fetching Customer Address. | |
$order = $booking->get_order(); | |
$customer_address = ''; | |
if ( $order ) { | |
$billing_address_1 = $order->get_billing_address_1(); | |
$billing_address_2 = $order->get_billing_address_2(); | |
$customer_address = $billing_address_1 . ' ' . $billing_address_2; | |
$fees = $order->get_fees(); | |
// Initialize an array to store fees information | |
$fees_info = array(); | |
// Loop through each fee | |
foreach ($fees as $fee) { | |
// Get fee name and amount | |
$fee_name = $fee->get_name(); | |
$fee_amount = $fee->get_total(); | |
// Add fee information to the array | |
$fees_info[] = "$fee_name: $fee_amount"; | |
} | |
// Combine fees information into a single string | |
$invoice = implode('| ', $fees_info); | |
// Get the shipping methods | |
$shipping_methods = $order->get_shipping_methods(); | |
// Initialize an array to store shipping information | |
$shipping_info = array(); | |
// Loop through each shipping method | |
foreach ($shipping_methods as $shipping_method) { | |
// Get shipping method name and amount | |
$shipping_name = $shipping_method->get_name(); | |
$shipping_amount = $shipping_method->get_total(); | |
// Add shipping information to the array | |
$shipping_info[] = "$shipping_name: $shipping_amount"; | |
} | |
// Combine shipping information into a single string | |
$delivery = implode('| ', $shipping_info); | |
} | |
//Adding Customer Email infomration after Booked By column data. | |
$row = $status . ',' . $booking_id . ',"' . $product_name . '",' . $booked_by . ',' . $invoice . ',' . $delivery . ',' . $customer_address . ',' . $order_id . ',"' . $start_date . '","' . $end_date . '","' . $persons . '",' . $quantity . ',' . $order_date . ',"' . $final_amt . '",' . $meeting_link; | |
return $row; | |
} | |
add_filter( 'bkap_bookings_csv_individual_row_data', 'bkap_bookings_csv_individual_data', 10, 4 ); | |
/* Adding Booking Data to Print td */ | |
function bkap_view_bookings_print_individual_row_data( $print_data_row_data_td, $booking, $booking_id, $data ) { | |
extract( $data ); | |
// Fetching Customer Email. | |
$customer = $booking->get_customer(); | |
$customer_email = $customer->email; | |
// Fetching Customer Address. | |
$order = $booking->get_order(); | |
$customer_address = ''; | |
if ( $order ) { | |
$billing_address_1 = $order->get_billing_address_1(); | |
$billing_address_2 = $order->get_billing_address_2(); | |
$customer_address = $billing_address_1 . ' ' . $billing_address_2; | |
$fees = $order->get_fees(); | |
// Initialize an array to store fees information | |
$fees_info = array(); | |
// Loop through each fee | |
foreach ($fees as $fee) { | |
// Get fee name and amount | |
$fee_name = $fee->get_name(); | |
$fee_amount = $fee->get_total(); | |
// Add fee information to the array | |
$fees_info[] = "$fee_name: $fee_amount"; | |
} | |
// Combine fees information into a single string | |
$invoice = implode('| ', $fees_info); | |
// Get the shipping methods | |
$shipping_methods = $order->get_shipping_methods(); | |
// Initialize an array to store shipping information | |
$shipping_info = array(); | |
// Loop through each shipping method | |
foreach ($shipping_methods as $shipping_method) { | |
// Get shipping method name and amount | |
$shipping_name = $shipping_method->get_name(); | |
$shipping_amount = $shipping_method->get_total(); | |
// Add shipping information to the array | |
$shipping_info[] = "$shipping_name: $shipping_amount"; | |
} | |
// Combine shipping information into a single string | |
$delivery = implode('| ', $shipping_info); | |
} | |
// Adding Customer Email after Booked by column data. | |
$print_data_row_data_td = ''; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $status . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $booking->id . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $product_name . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $booked_by . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $invoice . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $delivery . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $customer_address . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $booking->order_id . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $start_date . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $end_date . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $persons . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $quantity . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $order_date . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;">' . $final_amt . '</td>'; | |
$print_data_row_data_td .= '<td style="border:1px solid black;padding:5px;"><small>' . $meeting_link . '</small></td>'; | |
return $print_data_row_data_td; | |
} | |
add_filter( 'bkap_view_bookings_print_individual_row_data', 'bkap_view_bookings_print_individual_row_data', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment