2015-02-04 5 views
0

저는 PHP 프로그래머가 아니며, 이유를 파악하는 데 영원히 걸립니다. 그래서 잘하면 SO는 나를 도울 수 있었다. 기본적으로 interfax-woocommerce라는 woocommerce 플러그인을 설치했습니다.이 플러그인은 주문 완료 이메일을 팩스 번호로 전송하는 데 사용됩니다. 문서에서 플러그인은 주문 완료 템플릿을 사용하여 팩스를 보냅니다. 주문 메모 필드를 벗어나는 경우를 제외하고는 주문 이메일 템플릿의 모든 것을 포함합니다. 나는 그것이 플러그인과 관련이 있어야한다고 생각한다. 어쩌면 그것은 특정 주문 메모 필드를 포함하지 않고 주문 배열을 전달합니까? 나는 그것을 고치는 이유와 방법을 이해할 수 없다. 다음은 인테르 플러그인 여기워드 프레스 woocommerce interfax는 누락 된 필드가있는 팩스를 보냅니다.

if (! defined('ABSPATH')) exit; 

class WooCommerce_InterFax_Integration { 
    private $dir; 
    private $file; 
    private $assets_dir; 
    private $assets_url; 
    private $settings; 
    private $interfax_class; 
    private $username; 
    private $password; 
    private $store_fax_number; 
    private $template_html; 
    private $heading; 
    private $send_store_fax; 
    private $order; 
    private $fax_number; 

    public function __construct($file) { 
     $this->dir = dirname($file); 
     $this->file = $file; 
     $this->assets_dir = trailingslashit($this->dir) . 'assets'; 
     $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $file))); 

     // Add settings link to plugin page 
     add_filter('plugin_action_links_' . plugin_basename($this->file), array($this, 'add_settings_link')); 

     // Get integration settings 
     $this->settings = get_option('woocommerce_interfax_settings'); 

     // Only handle actions if integration is enabled 
     if($this->settings['wcif_enable'] == 'yes') { 
      $this->interfax_class = 'http://ws.interfax.net/dfs.asmx?wsdl'; 
      $this->username = $this->settings['wcif_username']; 
      $this->password = $this->settings['wcif_password']; 
      $this->store_fax_number = $this->settings['wcif_fax_number']; 
      $this->template_html = 'emails/customer-completed-order.php'; 
      $this->heading = __('Your order is complete', 'woocommerce'); 
      $this->send_store_fax = true; 

      // Add fax number field to checkout 
      add_filter('woocommerce_checkout_fields', array($this, 'add_checkout_field')); 

      // Send fax on selected order status (deault to 'completed' if no status is selected) 
      if($this->settings['wcif_fax_status']) { 
       $fax_status = $this->settings['wcif_fax_status']; 
      } else { 
       $fax_status = 'completed'; 
      } 
      add_action('woocommerce_order_status_' . $fax_status, array($this, 'trigger')); 

      // Add order action to dashboard 
      add_filter('woocommerce_order_actions', array($this, 'add_order_action')); 

      // Handle order actions 
      add_action('woocommerce_order_action_send_customer_fax', array($this, 'process_order_action_customer')); 
      add_action('woocommerce_order_action_send_store_fax', array($this, 'process_order_action_store')); 

      // Add fax number field to user profile page in WP dashboard 
      add_filter('woocommerce_customer_meta_fields', array($this, 'add_user_meta_field')); 

      // Add fax number field to edit billing address page 
      add_filter('woocommerce_billing_fields', array($this, 'add_address_field'), 10, 2); 
     } 

     // Handle localisation 
     $this->load_plugin_textdomain(); 
     add_action('init', array($this, 'load_localisation'), 0); 

    } 

    public function trigger($order_id) { 
     if ($order_id) { 
      $this->order = new WC_Order($order_id); 

      // Send fax to store owner 
      if($this->store_fax_number && strlen($this->store_fax_number) > 0) { 
       $this->send_store_fax(); 
      } 

      // Send fax to customer 
      $this->fax_number = get_post_meta($order_id, '_billing_fax', true); 
      if($this->fax_number && strlen($this->fax_number) > 0) { 
       $this->send_customer_fax(); 
      } 
     } 
    } 

    private function send_customer_fax() { 
     $interfax_client = new SoapClient($this->interfax_class); 

     $params->Username = $this->username; 
     $params->Password = $this->password; 
     $params->FaxNumber = $this->fax_number; 
     $params->Data  = $this->get_fax_content(); 
     $params->FileType = 'HTML'; 

     $result = $interfax_client->SendCharFax($params); 

     if(isset($result->SendCharFaxResult) && $result->SendCharFaxResult > 0) { 
      return true; 
     } 

     return false; 
    } 

    private function send_store_fax() { 
     $interfax_client = new SoapClient($this->interfax_class); 

     $params->Username = $this->username; 
     $params->Password = $this->password; 
     $params->FaxNumber = $this->store_fax_number; 
     $params->Data  = $this->get_fax_content(); 
     $params->FileType = 'HTML'; 

     $result = $interfax_client->SendCharFax($params); 

     if(isset($result->SendCharFaxResult) && $result->SendCharFaxResult > 0) { 
      return true; 
     } 

     return false; 
    } 

    public function get_fax_content() { 
     global $woocommerce; 

     ob_start(); 

     $template_data = array(
      'order'   => $this->order, 
      'email_heading' => $this->heading 
     ); 

     if(version_compare($woocommerce->version, '2.1-beta-1', ">=")) { 
      wc_get_template($this->template_html, $template_data); 
     } else { 
      woocommerce_get_template($this->template_html, $template_data); 
     } 

     return ob_get_clean(); 
    } 

    public function add_checkout_field($fields) { 

     $fields['billing']['billing_fax'] = array(
      'label'    => __('Fax Number (including country code)', 'wc_interfax'), 
      'placeholder'  => _x('e.g. +27861234567', 'placeholder', 'wc_interfax'), 
      'required'   => false, 
      'class'    => array('form-row'), 
      'clear'    => false 
     ); 

     return $fields; 

    } 

    public function add_order_action($actions) { 
     $actions['send_customer_fax'] = 'Send customer fax'; 
     $actions['send_store_fax'] = 'Send store fax'; 
     return $actions; 
    } 

    public function process_order_action_customer($order) { 
     $this->fax_number = get_post_meta($order->id, '_billing_fax', true); 
     if($this->fax_number && strlen($this->fax_number) > 0) { 
      $this->order = $order; 
      $this->send_customer_fax(); 
     } 
    } 

    public function process_order_action_store($order) { 
     if($this->store_fax_number && strlen($this->store_fax_number) > 0) { 
      $this->order = $order; 
      $this->send_store_fax(); 
     } 
    } 

    public function add_user_meta_field($fields) { 

     $fields['billing']['fields']['billing_fax'] = array(
      'label' => __('Fax number', 'wc_interfax'), 
      'description' => '' 
     ); 

     return $fields; 

    } 

    public function add_address_field($fields, $country) { 

     $fields['billing_fax'] = array(
      'label'   => __('Fax Number (including country code)', 'wc_interfax'), 
      'placeholder' => _x('e.g. +27861234567', 'placeholder', 'wc_interfax'), 
      'required'  => false, 
      'class'   => array('form-row'), 
      'clear'   => true 
     ); 

     return $fields; 
    } 

    public function add_settings_link($links) { 
     $settings_link = '<a href="admin.php?page=woocommerce&tab=integration&section=interfax">' . __('Configure', 'wc_interfax') . '</a>'; 
     array_unshift($links, $settings_link); 
     return $links; 
    } 

    public function load_localisation() { 
     load_plugin_textdomain('wc_interfax' , false , dirname(plugin_basename($this->file)) . '/lang/'); 
    } 

    public function load_plugin_textdomain() { 
     $domain = 'wc_interfax'; 
     $locale = apply_filters('plugin_locale' , get_locale() , $domain); 

     load_textdomain($domain , WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo'); 
     load_plugin_textdomain($domain , FALSE , dirname(plugin_basename($this->file)) . '/lang/'); 
    } 
+0

당신은 이것에 대한 답변을 얻지 못할 것입니다. 불행히도 팩스에 포함시키려는 값이 위에 있지 않으면 원래의 플러그인을 살펴보고 값을 사용할 수있는 위치를 찾아야하며 PHP 프로그래머가 필요합니다. 만약 당신이 구글 프로그래머가 당신을 위해 이것을 할 사람을 찾을 수 있어야합니다. – David

+0

데이빗, 귀하의 의견을 보내 주셔서 감사합니다. 위의 코드는 원본 플러그인의 실제 소스 코드입니다. 나는 add_filter ('woocommerce_checkout_fields', array ($ this, 'add_checkout_field'));라고 생각한다. woocommerce 문서 당 필터를 사용하여 모든 체크 아웃 필드를 포함하지만 팩스 플러그인에서 주문 노트 필드 값만 잡히지 않습니다. –

+0

'add_filter ('woocommerce_checkout_fields', array ($ this, 'add_checkout_field'));'는 체크 아웃 양식에만 팩스 번호 필드를 추가합니다. 이것은 주문서가 팩스에 나타나는지 여부와 관련이 없습니다. 팩스가'emails/customer-completed-order.php' 템플릿을 빌린 것 같습니다. 이 이메일에 주문 메모가 보이지 않으면 팩스에서도 주문 메모를 볼 수 없습니다. – helgatheviking

답변

1

의 소스 코드는 모든 이메일의 하단 (주문 포스트의 "발췌"입니다) 고객의 메모를 추가하는 예이다 :

add_action('woocommerce_email_after_order_table' , 'so_28333042_add_customer_note'); 
function so_28333042_add_customer_note($order){ 
    $post = get_post($order->id); 
    if($post->post_excerpt != ''){ 
     echo "<strong>Customer Note:</strong><br/>" . wp_kses_post($post->post_excerpt); 
    } 
} 

woocommerce_email_after_order_table 후크는 WooCommerce 2.3에서 사용 가능하지만, 으로 2.2+에서도 사용 가능하다고 생각합니다.

또는 customer-completed-order.php 템플릿을 테마에 복사하여 직접 작업 할 수 있습니다.

+0

나는 이것으로 주위를 찌르려고 노력하자. 감사. –

+0

로컬 서버에서 전자 메일을 보내지 않기 때문에 전자 메일 관련 질문을 테스트하기가 어려울만큼 게시가 가능합니다. – helgatheviking