2014-10-09 32 views
0

我已將Woocommerce預訂與Google日曆同步,以便員工(可訪問共享Google日曆)在客戶預訂旅程時即時看到。將Woocommerce預訂信息添加到Google日曆說明中的問題

我試圖獲得產品附加組件以顯示在描述中。到目前爲止唯一顯示的是資源和人數。下面的代碼會返回一個錯誤:

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

我只是爲了得到這個系統來適應我們的需要而學習我的方法。任何幫助或建議將不勝感激!

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和地方的簡短描述到谷歌日曆的說明,所以我會嘗試下一次。

我仍然在這一點,尋找一些其他網站後撐着走試過以下

$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的支持人員。我會在這裏報告,其他人正在試圖做與我一樣的事情。

+0

我試圖重新使用一些客戶預約,confirmed.php文件中找到的電子郵件文件夾中的代碼,因爲這增加了產品的附加組件給客戶的電子郵件確認。但也想到公共功能addon_price也得到了$ cart_item_data並將其添加到購物車的最終價格。這也會顯示相同的產品添加註釋,並且可以在產品插件插件中找到。 – Jon 2014-10-09 16:05:49

回答

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標籤和所有的客戶信息後,真的很好顯示在一個私人谷歌日曆的全體工作人員參考。回想起來,我當然在一個圈子裏工作。我已經忘記了。

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