我正在使用SMS API在woocommerce的Thankyou页面上向客户发送短信。 API在发送SMS后重定向到API提供的页面。我问他们一个解决方案,他们建议使用iframe。但重定向存在。然后,他们建议从页面结帐调用变量。我无法理解。请指导我。在这里,是我的代码。
function tz_send_message_to_customer($order_id){
$order = new WC_Order( $order_id );
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
$name = $order->billing_first_name . $order->billing_last_name;
// Configuration variables
$id = "xxxxx"; // Account Username
$pass = "xxxx"; // Account Password
$mask = "xxxx"; // Account Masking
// Data for text message
$to = $order->billing_phone; // Recipient Number with "92" Pakistan Code
$message = urlencode("Dear " . $name . "!" . "Your following Order is Under Process" . "Order ID: " .$order_id . "Total: " . $currency.$total. "Thankyou For Shopping") ;
// Prepare data for POST request - DO NOT EDIT
$data = "id=".$id."&pass=".$pass."&msg=".$message."&to=".$to."&lang=English"."&mask=".$mask."&type=xml";
// Send the POST request with cURL - DO NOT EDIT
//header("location:http://ip-address/api/sendsms.php?".$data);
$url = "http://ip-address/api/sendsms.php?".$data;
?>
<iframe src="<?php echo $url; ?>"></iframe>
<?php
}
add_action( 'woocommerce_thankyou', 'tz_send_message_to_customer', 10, 1 );
答案 0 :(得分:1)
我通过在Google上搜索找到了解决方案。有人建议在iframe中使用sandbox属性,例如sandbox =“allow-same-origin”。因此,iframe代码看起来像
<iframe src="<?php echo $url; ?>" sandbox="allow-same-origin" style=" display: none;"></iframe>
可在以下网址找到更多信息:https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/