Woocommerce Checkout功能

时间:2017-11-19 06:39:01

标签: wordpress woocommerce

我想在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);

我没有找到结帐流程页面。

1 个答案:

答案 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);
}