亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

訂單完成后 WooCommerce 觸發 URL

訂單完成后 WooCommerce 觸發 URL

PHP
LEATH 2022-07-16 18:43:27
是否可以在訂單完成后觸發 URL。它不是客戶應該發送到的 URL,但在后端應該訪問此 URL,以便調用 API。我對此有點陌生,所以不知道這是否是正確的方法。如果有人能指出我正確的方向,那就太好了。我得到了這個應該被觸發的 URL,其中填充了我在完成訂單后應該得到的變量:https:///v1/invite/externalhash=XXX&location_id=XXX&tenantId=XX&invite_email=XXX&delay=X&first_name=XXX&last_name=XXX&language=XX&ref_code=XXXX邀請電子郵件 -> 這應該是下訂單的電子郵件first_name -> 這應該是下訂單的名稱last_name -> 這應該是下訂單的姓氏語言 -> 這應該是訂單發貨國家的語言代碼(小寫)我知道這很多,但我應該怎么做?編輯 好的,我找到了一種使用 CURL 執行此操作的方法,但是如何在不在瀏覽器中打開 URL 的情況下執行以下代碼?// create a new cURL resource$ch = curl_init();// set URL and other appropriate optionscurl_setopt($ch, CURLOPT_URL, "http://www.example.com/");curl_setopt($ch, CURLOPT_HEADER, 0);// grab URL and pass it to the browsercurl_exec($ch);// close cURL resource, and free up system resourcescurl_close($ch);我只想執行 URL 但不想在我的瀏覽器中打開它。只是一個快速的電話,就是這樣。CURL 可以做到這一點嗎?編輯 2.0.1我在訂單狀態完成后更改了我的功能。我幾乎可以正常工作,但由于某種原因,在使用“動態”網址時,不會觸發網址。我還在 javascript 中添加了一個回顯警報,這個警報傳遞了準確的動態 URL,因此它可以正常工作。在帶有警報的功能下方: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();        $achternaam = $order->get_billing_last_name();        $email = $order->get_billing_email();        echo '<script type="text/javascript">alert("https://klantenvertellen.nl/v1/invite/external?hash=0926-4adb-a39e-d04110d1e445&location_id=104679&tenantId=99&invite_email='.$email.'&delay=1&first_name='.$voornaam.'&last_name='.$achternaam.'&language=nl");</script>';
查看完整描述

2 回答

?
HUWWW

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);

    // ...

}


查看完整回答
反對 回復 2022-07-16
?
狐的傳說

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。


希望這可以幫助其他想要這樣做的人。


查看完整回答
反對 回復 2022-07-16
  • 2 回答
  • 0 關注
  • 326 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號