2016-10-18 1 views
0

WC_Gateway_BACS 확장 클래스의 재정의 기능을 추가했습니다. 이 기능은 주문 상태를 보류에서 처리로 업데이트합니다. 문제는 이메일에 은행 세부 정보가 누락되었습니다. 이메일에 은행 계좌 번호가 포함되기 전에 맞춤 설정 이후에 이메일에 해당 은행 계좌 번호가 포함되지 않았기 때문에 주문 상태가 처리 중이기 때문에 생각합니다.Woocommerce BACS는 이메일 처리시 은행 계좌 번호를 추가합니다.

누구나 같은 일을하고 해결책을 찾았습니까? 여기에 보류 중이거나 이메일 처리 중 일부 이미지가 포함되었습니다. 나는 실제로 오늘 같은 문제로 실행

class WC_Gateway_BACS_custom extends WC_Gateway_BACS { 
    /** 
    * Process the payment and return the result 
    * 
    * @access public 
    * @param int $order_id 
    * @return array 
    */ 
    function process_payment($order_id) { 
     global $woocommerce; 
     $order = new WC_Order($order_id); 
     // Mark as processing (or anything you want) 
     $order->update_status('processing', __('Awaiting BACS payment', 'woocommerce')); 

     // Reduce stock levels 
     $order->reduce_order_stock(); 

     // Remove cart 
     $woocommerce->cart->empty_cart(); 

     // Return thankyou redirect 
     return array(
      'result' => 'success', 
      'redirect' => $this->get_return_url($order) 
     ); 
    } 

    /** 
    * Add content to the WC emails. 
    * 
    * @param WC_Order $order 
    * @param bool $sent_to_admin 
    * @param bool $plain_text 
    */ 
    // public function email_instructions($order, $sent_to_admin, $plain_text = false) { 

    // if (! $sent_to_admin && 'bacs' === $order->payment_method && ($order->has_status('on-hold') || $order->has_status('processing'))) { 
    //  if ($this->instructions) { 
    //   echo wpautop(wptexturize($this->instructions)) . PHP_EOL; 
    //  } 
    //  $this->bank_details($order->id); 
    // } 

    // } 
} 

on-hold email processing email

답변

0

처리 - 이메일에 계좌 번호를 추가. 위처럼,

클래스를 확장 :

/* override gateway for BACS */ 
function my_core_gateways($methods) 
{ 
    foreach ($methods as &$method){ 
    if($method == 'WC_Gateway_BACS') 
    { 
     $method = 'WC_Gateway_BACS_custom'; 
    } 
    } 
    return $methods; 
} 

/* custom gateway processor for BACS */ 
class WC_Gateway_BACS_custom extends WC_Gateway_BACS 
{ 

    /** 
    * Add content to the WC emails. 
    * 
    * @param WC_Order $order 
    * @param bool $sent_to_admin 
    * @param bool $plain_text 
    */ 
    public function email_instructions($order, $sent_to_admin, $plain_text = false) { 

     if (! $sent_to_admin && 'bacs' === $order->payment_method && $order->has_status('processing')) { 
      if ($this->instructions) { 
       echo wpautop(wptexturize($this->instructions)) . PHP_EOL; 
      } 

     /* dirty hack to get access to bank_details */ 
     $reflector = new ReflectionObject($this); 
     $method = $reflector->getMethod('bank_details'); 
     $method->setAccessible(true); 

     $result = $method->invoke($this, $order->id); 
     } 
    } 

    /** 
    * Process the payment and return the result. 
    * 
    * @param int $order_id 
    * @return array 
    */ 
    public function process_payment($order_id) { 

     $order = wc_get_order($order_id); 

     // Mark as on-hold (we're awaiting the payment) 
     $order->update_status('processing', __('Awaiting BACS payment', 'woocommerce')); 

     // Reduce stock levels 
     $order->reduce_order_stock(); 

     // Remove cart 
     WC()->cart->empty_cart(); 

     // Return thankyou redirect 
     return array(
      'result' => 'success', 
      'redirect' => $this->get_return_url($order) 
     ); 
    } 
} 

또는 내 의견 청소기, 두 가지 작업

add_action('woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2); 
add_action('woocommerce_thankyou', 'bacs_order_payment_processing_order_status', 10, 1); 

function bacs_order_payment_processing_order_status($order_id) 
{ 
    if (! $order_id) { 
    return; 
    } 

    $order = new WC_Order($order_id); 

    if ('bacs' === $order->payment_method && ('on-hold' == $order->status || 'pending' == $order->status)) { 
    $order->update_status('processing'); 
    } else { 
    return; 
    } 
} 

function add_order_email_instructions($order, $sent_to_admin) { 

    if (! $sent_to_admin && 'bacs' === $order->payment_method && $order->has_status('processing')) { 
    $gw = new WC_Gateway_BACS(); 

    $reflector = new ReflectionObject($gw); 
    $method = $reflector->getMethod('bank_details'); 
    $method->setAccessible(true); 

    $result = $method->invoke($gw, $order->id); 
    } 
} 

두 번째 솔루션은이를 추가하여 나는 두 가지 솔루션을 함께했다 장기적으로 최소 유지 보수 요구 사항.

관련 문제