2016-10-18 5 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

処理、電子メールに口座番号を追加したいです。第二の溶液が持つ二つの動作

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); 
    } 
} 

を追加することにより、

/* 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) 
     ); 
    } 
} 

それとも、私の意見でクリーナーを、:あなたは上記したよう、クラスの拡張

:私は2つの可能な解決策を思い付きました長期的には最小のメンテナンス要件

関連する問題