如何在 woocommerce 中处理付款之前获取帐单地址?
Posted
技术标签:
【中文标题】如何在 woocommerce 中处理付款之前获取帐单地址?【英文标题】:How to get the billing address before process payment in woocommerce? 【发布时间】:2019-06-17 00:27:36 【问题描述】:在处理付款之前,我必须从付款服务器获取结帐令牌。如何获取用户帐户和访客帐户的帐单地址。是否可以获取帐单地址信息。我正在做一个 cusotm 支付网关插件。
public function curlrequest()
$data = array(
"page_id" => $this->page_id,
"Currency" => get_woocommerce_currency(),
"amount" => '100',
"datetime_utc" => date('Y-m-d H:i:s'),
"transaction_type" => "authorize",
"billing_address"=>('first_name'=>'','lastname'=>'') // need to pass here
);
$data_string = json_encode($data);
$ch = curl_init('https://xxxxxxxxxx/paymentgateway');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic '. base64_encode("$this->api_username".':'."$this->api_password"),
'Content-Length: ' . strlen($data_string))
);
return respone token;
public function payment_fields()
echo '<input id="checkout_token" name="checkout_token" type="hidden" value="'.$this->curlrequest().'" />';
//other cc common fields
【问题讨论】:
【参考方案1】:尝试使用WC_Customer
方法,例如:
$billing_first_name = WC()->customer->get_billing_first_name();
$billing_last_name = WC()->customer->get_billing_last_name();
$billing_address_1 = WC()->customer->get_billing_address_1();
$billing_address_2 = WC()->customer->get_billing_address_2();
$billing_postcode = WC()->customer->get_billing_postcode();
$billing_city = WC()->customer->get_billing_city();
$billing_state = WC()->customer->get_billing_state();
$billing_country = WC()->customer->get_billing_country();
或WC_Session
客户数据,可以使用以下方式访问:
$customer_data = WC()->session->get('customer');
$billing_first_name = $customer_data['first_name'];
$billing_last_name = $customer_data['last_name'];
$billing_address_1 = $customer_data['address_1'];
$billing_address_2 = $customer_data['address_2'];
$billing_postcode = $customer_data['postcode'];
$billing_city = $customer_data['city'];
$billing_state = $customer_data['state'];
$billing_country = $customer_data['country'];
【讨论】:
以上是关于如何在 woocommerce 中处理付款之前获取帐单地址?的主要内容,如果未能解决你的问题,请参考以下文章
在 WooCommerce 中自动处理已付款订单而不是自动完成