2 回答

TA贡献1874条经验 获得超12个赞
您可以woocommerce_payment_complete像这样使用该操作:
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {
// Get the order info
$order = new WC_Order( $order_id );
// Your custom logic here, for instance calling the url with curl
$ch = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// ...
}

TA贡献1804条经验 获得超3个赞
完成订单后,我终于在我的functions.php中使用了这个函数。
add_action('woocommerce_order_status_completed', 'custom_process_order');
function custom_process_order($order_id) {
// Get the order info
$order = wc_get_order( $order_id );
if($order->get_billing_country() == "NL"){
// create a new cURL resourc
$ch = curl_init();
$voornaam = $order->get_billing_first_name();
$voornaam_new = str_replace(' ', '%20', $voornaam);
$achternaam = $order->get_billing_last_name();
$achternaam_new = str_replace(' ', '%20', $achternaam);
$email = $order->get_billing_email();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, 'https://klantenvertellen.nl/v1/invite/external?hash=0926-4adb-a39e-d04110d1e445&location_id=104679&tenantId=99&invite_email='.$email.'&delay=1&first_name='.$voornaam_new.'&last_name='.$achternaam_new.'&language=nl');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
}
}
我还添加了一个 if 语句,因为我只想在客户从荷兰订购时触发它。问题在于名字或姓氏中的空格,因此我将它们替换为带有 str_replace 的 %20。
希望这可以帮助其他想要这样做的人。
- 2 回答
- 0 关注
- 349 浏览
添加回答
举报