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 關注
- 326 瀏覽
添加回答
舉報