将Woocommerce预订信息添加到Google日历说明中的问题

时间:2014-10-09 14:14:43

标签: wordpress woocommerce google-calendar-api

我已将Woocommerce预订与Google日历同步,以便员工(可以访问共享的Google日历)可以在客户预订旅行时立即查看。

我试图让产品附加组件也出现在说明中。到目前为止,唯一出现的是资源和人数。以下代码启动了一个错误:

  

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

我只是在学习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;

        }
    }

编辑

我尝试添加结算电子邮件和结算电话但仍然无法正确使用。我在Google日历中看到的只是电子邮件,后跟空格。

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

上面代码中的wp_kses_post方法会返回WooCommerce中的简短说明并放入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的支持。我会在这里报告,其他人正试图和我做同样的事情。

1 个答案:

答案 0 :(得分:0)

我能够通过从email_orders_table中提取所有订单信息来解决问题。我发布了我的答案,以防其他人试图做同样的事情。 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标记后非常有效,并且所有访客信息都显示在私人Google日历中,供整个职员参考。回想起来,我肯定在一个圈子里工作过。我忘了。

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