Wordpress 将Woocommerce预订信息添加到Google日历描述中时出现问题

Wordpress 将Woocommerce预订信息添加到Google日历描述中时出现问题,wordpress,woocommerce,google-calendar-api,Wordpress,Woocommerce,Google Calendar Api,我已经将Woocommerce预订与Google日历同步,这样员工(可以访问共享的Google日历)可以在客户预订行程时立即看到 我试图让产品附加组件也出现在描述中。到目前为止,唯一出现的是资源和人员。以下代码返回一个错误: 致命错误:在第454行的/home/content/12/10265512/html/wp content/plugins/woocommerce bookings/includes/integrations/class-wc-bookings-google-calenda

我已经将Woocommerce预订与Google日历同步,这样员工(可以访问共享的Google日历)可以在客户预订行程时立即看到

我试图让产品附加组件也出现在描述中。到目前为止,唯一出现的是资源和人员。以下代码返回一个错误:

致命错误:在第454行的/home/content/12/10265512/html/wp content/plugins/woocommerce bookings/includes/integrations/class-wc-bookings-google-calendar-integration.php中对非对象调用成员函数get_order_item_totals()

为了让这个系统满足我们的需要,我正在学习PHP。如有任何帮助或建议,将不胜感激

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;

        }
    }
上面代码中的wp_kses_post方法确实会将WooCommerce和places的简短描述返回到Google日历描述中,所以我将在下一步尝试

我仍然在尝试这一点,在看过其他一些网站后,我尝试了以下方法

$description .= sprintf( __('%s', 'woocommerce'), $order->email_order_items_table( true, false, true )) . PHP_EOL;
用于通过电子邮件将相同的信息传递给站点管理员

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


我仍然收到一个对非对象上的成员函数的致命错误调用。几天前我联系了WooCommerce的支持人员。我将在这里报告,以防其他人试图做与我相同的事情。

我能够通过从email\u orders\u表中提取所有订单信息来解决问题。我正在发布我的答案,以防其他人试图做同样的事情。WooCommerce的客户支持部门无法帮助说明这超出了他们的支持政策,并考虑了自定义代码

// 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 ;
剥离HTML标签后,这项功能非常有效,所有的客人信息都显示在一个私有的谷歌日历中,供全体员工参考。回首往事,我的确是绕了一圈。我忘了

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

我试图重新使用电子邮件文件夹中customer-booking-confirm.php文件中的一些代码,因为这会将产品插件添加到客户电子邮件确认中。但也考虑到公共函数addon_price也会获取用户的$cart_item_数据,并将其添加到carts的最终价格中。这也会显示相同的产品附加说明,可以在产品附加说明插件中找到。
 do_action( 'woocommerce_email_after_order_table', $order, true, false );