2017-05-03 43 views
0

我正在为Woo开发支付网关,并尝试使用woocommerce_receipt_挂钩提交自定义表单并将客户重定向到第三方网络支付服务。任何人都知道为什么钩子不起作用。感谢您的帮助!干杯!Woocommerce收据挂钩无法正常工作

这是我的支付类代码:

class my_vpos extends WC_Payment_Gateway { 
    function __construct() { 

     // The global ID for this Payment method 
     $this->id = "my_vpos"; 


     $this->method_title = __("my_vpos", 'my_vpos'); 


     $ this->method_description = __("Payment Gateway Plug-in for 
     WooCommerce", 'my_vpos'); 
     $this->title = __("my_vpos", 'my_vpos'); 


     $this->has_fields = false; 

     // This basically defines your settings which are then loaded with 
     init_settings() 
    $this->init_form_fields(); 

    $this->title = $this->get_option('title'); 
    $this->init_settings(); 


    $this->testurl = 'https://www.exaple-payment.com/pay-gw-t/vpos'; 
    $this->liveurl = 'https://www.exaple-payment.com/pay-gw-t/vpos'; 

    // Actions 


    add_action('woocommerce_receipt_' . $this->id, array($this, 
    'receipt_page')); 
} // End __construct() 


    function receipt_page($order){ 
     echo '<form action="' . $this->testurl . '" method="post" 
     id="submit_payment_form"> 
      <input type="hidden" name="type" value="PAYLOGIN"/> 
      </form>'; 
    } 
} 

回答

0

添加以下代码function.php文件

<?php 
    add_action('plugins_loaded', 'woocommerce_my_vpos_init', 0); 
    function woocommerce_my_vpos_init(){ 
     if(!class_exists('WC_Payment_Gateway')) return; 

     class WC_My_Vpos extends WC_Payment_Gateway{ 
     public function __construct(){ 
      $this -> id = 'my_vpos'; 
      $this -> medthod_title = 'My Vpos'; 
      $this -> has_fields = false; 

      $this -> init_form_fields(); 
      $this -> init_settings(); 

      $this -> title = "My Vpos"; 
      $this -> description = "Payment Gateway Plug-in for WooCommerce"; 

      $this -> testurl = 'https://www.exaple-payment.com/pay-gw-t/vpos'; 
      $this -> liveurl = 'https://www.exaple-payment.com/pay-gw-t/vpos'; 

      add_action('woocommerce_receipt_my_vpos', array(&$this, 'receipt_page')); 
      } 




     /** 
     * Receipt Page 
     **/ 
     function receipt_page($order){ 
      echo '<form action="' . $this->testurl . '" method="post" 
       id="submit_payment_form"> 
        <input type="hidden" name="type" value="PAYLOGIN"/> 
        </form>'; 
     } 

     } 
     /** 
     * Add the Gateway to WooCommerce 
     **/ 
     function woocommerce_add_my_vpos_gateway($methods) { 
      $methods[] = 'WC_My_Vpos'; 
      return $methods; 
     } 

     add_filter('woocommerce_payment_gateways', 'woocommerce_add_my_vpos_gateway'); 
    } 
    ?> 
+0

我有插件结构,但'woocommerce_receipt_my_vpos'不行。 Thaks帮助。 – htmlbrewery

+0

尝试此代码 add_action('woocommerce_receipt_my_vpos',array(&$ this,'receipt_page'),10,1); –

+0

没有成功,点击'下订单'按钮网站后出现错误'Internal Server Error' – htmlbrewery