Problems Adding Woocommerce Bookings info into the Description of Google Calendar

I have synched Woocommerce Bookings with Google Calendar so that employees (with access to a shared Google Calendar) can see instantly when a customer books a trip.

I’m trying to get product add-ons to show up in the description as well. So far the only thing showing up are resources and # of persons. The following code kicks back an error:

Read More

Fatal error: Call to a member function get_order_item_totals() on a non-object in /home/content/12/10265512/html/wp-content/plugins/woocommerce-bookings/includes/integrations/class-wc-bookings-google-calendar-integration.php on line 454

I’m just learning my way around PHP out of necessity to get this system to fit our needs. Any help or suggestions would be / are greatly appreciated!

public function sync_booking( $booking_id ) {
    $event_id     = get_post_meta( $booking_id, '_wc_bookings_gcalendar_event_id', true );
    $booking      = get_wc_booking( $booking_id );
    $api_url      = $this->calendars_uri . $this->calendar_id . '/events';
    $access_token = $this->get_access_token();
    $timezone     = wc_booking_get_timezone_string();
    $product      = $booking->get_product();
    $summary      = '#' . $booking->id . ' - ' . $product->get_title();
    $description  = '';

    // Add resources in description

        if ( $resource = $booking->get_resource() ) {
        $description .= __( 'Resource #', 'woocommerce-bookings' ) . $resource->ID . ' - ' . $resource->post_title;
    }

    // Add ProductAdd on in description testing this 

  if ( $totals = $order->get_order_item_totals() ) {
            $i = 0;
            foreach ( $totals as $total ) {
                $i++;

                    if ( $i == 1 ) {

                    $description .= sprintf($total['label']) . PHP_EOL;
                    $description .= sprintf($total['value']) . PHP_EOL;
                }
            }
        }   


    // Add persons in description
    if ( $booking->has_persons() ) {
        $description .= ( '' != $description ) ? PHP_EOL . PHP_EOL : '';

        foreach ( $booking->get_persons() as $id => $qty ) {
            if ( 0 === $qty ) {
                continue;
            }

            $person_type = ( 0 < $id ) ? get_the_title( $id ) : __( 'Person(s)', 'woocommerce-bookings' );
            $description .= sprintf( __( '%s: %d', 'woocommerce-bookings'), $person_type, $qty ) . PHP_EOL;
            $description .= wp_kses_post( $product->post->post_excerpt, array() ) . PHP_EOL;
            $description .= sprintf("ADDITIONAL NOTES:") . PHP_EOL;
            $description .= sprintf("Hey John passing static notes to Calender test") . PHP_EOL;

        }
    }

Edit

I tried adding Billing Email and Billing Phone and still cannot get it right. All I see in Google Calendar is Email followed by blank space.

$description .= sprintf( __('Email: %s', 'woocommerce'), $order->billing_email ) . PHP_EOL;
$description .= sprintf( __('Phone: %s', 'woocommerce'), $order->billing_phone ) . PHP_EOL;

the wp_kses_post method in the code up above does return the short description from WooCommerce and places into the Google Calendar description so I will try that next.

I’m still pluggin away at this and after looking at some other websites tried the following

$description .= sprintf( __('%s', 'woocommerce'), $order->email_order_items_table( true, false, true )) . PHP_EOL;

Which is used to pass the same information on in an email to the site admin.

<?php echo $order->email_order_items_table( true, false, true ); ?>

I’m still getting a Fatal Error call to a member function on a non-object. I contacted support at WooCommerce a few days ago. I’ll report back here incase someon else is trying to do the same thing as me.

Related posts

Leave a Reply

1 comment

  1. I was able to solve the issue by pulling all order info from the email_orders_table. I’m posting my answer in case someone else is attempting to do the same thing. Customer Support at WooCommerce was unable to help stating it was outside of their support policy and considered custom code.

    // Add First Name of Guest
    $description .= sprintf( __( 'NAME: %s', 'woocommerce-bookings' ), $booking->get_order()->billing_first_name ) . PHP_EOL;
    // Add their email address
    $description .= sprintf( __('EMAIL: %s', 'woocommerce-bookings'), $booking->get_order()->billing_email ) . PHP_EOL;
    // Add their Phone Number
    $description .= sprintf( __('PHONE: %s', 'woocommerce-bookings'), $booking->get_order()->billing_phone ) . PHP_EOL;
    // Purchase Notes and WooCommerce Product Add Ons
    $description .= sprintf("ADDITIONAL NOTES:") . PHP_EOL;
    $description .= sprintf ( __('%s', 'woocommerce-bookings'), strip_tags($order->email_order_items_table( $order->is_download_permitted(), true, true ))) . PHP_EOL ;
    

    This works really well after stripping the HTML tags and all the Guest information is shown in a Private Google Calendar for the entire Staff to Reference. Looking back I certainly worked around in a circle. I had forgotten.

     do_action( 'woocommerce_email_after_order_table', $order, true, false );