Woocommerce收据挂钩不能正常工作

时间:2017-05-03 11:42:46

标签: php wordpress woocommerce hook-woocommerce

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

这是我的付款类代码:

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

1 个答案:

答案 0 :(得分: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' );
    }
    ?>