【问题标题】:Custom WooCommerce Gateway自定义 WooCommerce 网关
【发布时间】:2015-05-09 16:13:14
【问题描述】:

我正在尝试为 WooCommerce 插件开发自定义支付网关,但结帐页面出现问题。我想要的是在 5 秒后自动提交的结帐最后一步页面上插入一个表单。

我的代码是:

        ...
    add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
    add_action('woocommerce_api_wc_' . $this->id, array($this, 'handle_callback'));
}

function handle_callback() {
    wp_die('handle_callback');
}

function receipt_page( $order ) 
{   
    echo "receipt page";
    $this->generate_submit_form_elements( $order );
}

问题是“receipt_page”动作没有被触发。 谢谢!

【问题讨论】:

  • 你确定receipt_page 是一个真正的钩子吗?我听起来不熟悉。我以为最后一页是“woocommerce_thankyou”

标签: wordpress woocommerce


【解决方案1】:

哦,那是因为您忘记将 has_fields 标志设置为 true。

//after setting the id and method_title, set the has_fields to true
          $this -> id = 'kiwipay';
          $this -> method_title = 'KiwiPay';

          $this->has_fields = true; // if you want credit card payment fields to show on the users checkout page

然后在 process_payment 函数中输入:

// Payload would look something like this.
$payload = array(
"amount" => $order.get_total(), 
"reference" => $order->get_order_number(),
"orderid" => $order->id,
"return_url" => $this->get_return_url($order)  //return to thank you page.
);

response = wp_remote_post( $environment_url, array(
                'method'    => 'POST',
                'body'      => http_build_query( $payload ),
                'timeout'   => 90,
                'sslverify' => false,
            ) );

// Retrieve the body's response if no errors found
$response_body = wp_remote_retrieve_body( $response );
$response_headers = wp_remote_retrieve_headers( $response );

//use this if you need to redirect the user to the payment page of the bank.
$querystring = http_build_query( $payload );

return array(
            'result'   => 'success',
            'redirect' => $environment_url . '?' . $querystring,
        );

【讨论】:

  • 确实 has_fields 标志是问题所在。谢谢!
猜你喜欢
  • 2017-03-02
  • 2017-08-05
  • 2014-06-06
  • 2023-03-03
  • 2020-11-20
  • 2016-08-20
  • 2017-04-04
  • 2021-05-29
相关资源
最近更新 更多