我向 woocommerce_thankyou
添加了一个 Action ,其中有 45 秒的延迟,它导致页面在执行时挂起 45 秒。我想知道是否有某种方法可以将其与 woocommerce thankyou.php
页面构建后可能触发的操作 Hook 。我已经尝试在脚本末尾添加我自己的 do_action
但这没有用。该页面仍挂起 45 秒。
这是 Action 及其功能...
add_action('woocommerce_thankyou', 'call_restaurant');
function call_restaurant() {
sleep(45);
require_once '/home/mywebsite/public_html/voice/Services/call.php';
$sid = "bla bla bla";
$token = "bla bla bla";
$from_number = "3055551234"; // Calls must be made from a registered Twilio number.
$to_number = "3055551234";
$message = "Hello. You have received a new order from eat three sixty five miami dot com";
$client = new Services_Twilio($sid, $token, "2010-04-01");
/*
$call = $client->account->calls->create(
$from_number,
$to_number,
'http://twimlets.com/message?Message='.urlencode($message)
);
*/
echo 'phone call has been made';
}
我这样做的原因是因为我试图在下订单后 45 秒调用自动电话。
非常感谢任何帮助。
购物车在这里... http://www.eat365miami.com/lee-sushi/
最佳答案
我的解决方案是连接到 wordpress 页脚,并在我创建的操作功能中使用了一个 woocommerce 条件标签,如果我在“收到订单”页面上,它只会输出我的 ajax 请求。这是我在主题 functions.php 文件中创建的操作...
add_action('wp_footer', 'print_call_restaurant_javascript'); function print_call_restaurant_javascript() { if(is_wc_endpoint_url( 'order-received' )) { echo ' var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == XmlHttpRequest.DONE ) { if(xmlhttp.status == 200){ document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } else if(xmlhttp.status == 400) { alert(\'There was an error 400\'); } else { alert(\'something else other than 200 was returned\'); } } } xmlhttp.open("GET", "http://eat365miami.com/voice/call_restaurant.php?order_number=123", true); xmlhttp.send(); '; } }
我希望其他人能发现这个有用:)
关于wordpress - 在 wordpress 中构建页面后的 do_action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29808314/