我想在woocommerce结账时执行以下脚本。
$args = http_build_query(array(
'token' => '*********',
'from' => '****',
'to' => '*******',
'text' => 'Your Order Id is: 9879987 '));
$url = "http://api.sparrowsms.com/v2/sms/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
我没有找到结帐流程页面。
答案 0 :(得分:1)
您需要在woocommerce_after_checkout_form
中添加function.php
挂钩,如下所示。
add_action( 'woocommerce_after_checkout_form', 'sms_function', 10 );
function sms_function( ) {
$args = http_build_query(array(
'token' => '*********',
'from' => '****',
'to' => '*******',
'text' => 'Your Order Id is: 9879987 '));
$url = "http://api.sparrowsms.com/v2/sms/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
}