Woocommerce load an external page on thankyou page - php

I am using an SMS API to send sms to customer on Thankyou page of woocommerce. The API redirects to the API provide's page after sending the SMS. I asked them for a solution, they suggested to use the iframe. But the redirection exists. Then, they suggested to call variables from page checkout. I am unable to understand. Kindly, guide me. Here, is my code.
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 );

I have found the solution by searching on Google. It was suggested that use sandbox attribute in iframe like sandbox="allow-same-origin". So, the iframe code looks like as
<iframe src="<?php echo $url; ?>" sandbox="allow-same-origin" style=" display: none;"></iframe>
More info can be found at: https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/

Related

WooCommerce order received url link shortcode displays nothing

I am needing help on this custom code I have created. The purpose of this shortcode is to display a clickable link to the customers order received page on the order received email. I want the link to be accessible for all customers including those that do not have an account. The order status when order is placed is on-hold if that helps.
function emailurlorder()
{
$order = wc_get_order( $order_id );
if ( $order ) {
$order->get_checkout_order_received_url();
return;
{
$checkout_order_received_url = $order->get_checkout_order_received_url();
if ($order_checkout_order_received_url) {
return $order_checkout_order_received_url;
}
ob_start();
$pay_link = $checkout_order_received_url;
$payment_text = __('Click here to pay','text_domain');
echo '' . $payment_text . '';
$contents = ob_get_contents();
ob_end_clean();
return $contents; '' . $payment_text . '';
}
}
}
add_shortcode('orderlink','emailurlorder');
What it is suppose to do is display a clickable link labeled as "Click here to pay" and the url is my websites order received page for that specific order.
Problem- Shortcode displays absolutely nothing not even the shortcode text ([orderlink]).

Dynamically passing value to sms api in php?

This is my sms url
"https://example.com/api/sendhttp.php?authkey=#############&mobiles=".$mobile."&message=".urlencode($rem)."&sender=abcdef&route=#"
Here is my Code
<?php
session_start();
$mobile=98994564564;
$rem="Hi";
$url=$_SESSION['smsurl'];
echo $url;
?>
What I am trying to do here is I am calling this url through session variable. But when I am displaying the url, it is not getting value of $mobile and $rem.
It should display
"https://example.com/api/sendhttp.php?authkey=#############&mobiles=8994564564"&message=".urlencode("Hi")."&sender=abcdef&route=#"
The problem is, $_SESSION['smsurl'] does not contain the actual variables like $mobile or $rem, instead it contains the value of those variables. So you can't simply do $mobile=ABC; $rem="XYZ"; $url=$_SESSION['smsurl']; to change the query part of the URL.
The solution is,
Parse the URL
Change the query part of the URL
Reconstruct the URL again
So your code should be like this,
<?php
session_start();
$mobile=98994564564;
$rem="Hi";
$urlArray = parse_url($_SESSION['smsurl']);
parse_str($urlArray['query'], $qStringArray);
$qStringArray['mobiles'] = $mobile;
$qStringArray['message'] = urlencode($rem);
$qString = http_build_query($qStringArray);
$apiUrl = $urlArray['scheme'] . '://' . $urlArray['host'] . $urlArray['path'] . '?' . $qString;
// Display the final URL
echo $apiUrl;
?>

Convert PHP $text into clickable url link on frontend

I have added a script to my functions.php file in WordPress to generate additional text in the Woocommerce Thank-You page.
**
* Custom text on the receipt page.
*/
function isa_order_received_text( $text, $order ) {
$new = $text . ' A receipt has been sent to you via email.Please submit your ticket here:https://google.com';
return $new;
}
Part of the text is a link to another page.
Please submit your ticket here:https://google.com';
However, the link does not display as a highlighted/clickable URL on the frontend. How do I fix this?
Use a link inside your PHP string :
$new = $text . ' A receipt has been sent to you via email.Please submit your ticket here';
Try this
**
* Custom text on the receipt page.
*/
function isa_order_received_text( $text, $order ) {
$new = $text . ' A receipt has been sent to you via email.Please submit your ticket here';
return $new;
}
$new = $text . ' A receipt has been sent to you via email.Please submit your ticket here (https://google.com)';
return $new;

Wordpress: Don't manage to retrieve author's name from php function

I'm creating a function that sends an email to a mailing list when a post is published on my WordPress blog.
function announce_post($post_id){
$email_address = 'address.of#the-mailing.list';
$subject = "New Post: " . get_the_title($post_id);
$body = "Hi,\r\n\r\n" .
"SOMEONE has just published the article \"" .
get_the_title($post_id) . "\" on \"BLOG TITLE\".\r\n\r\n" .
"You can read it at " . get_permalink($post_id) . "\r\n" .
"or visit BLOG_ADDRESS.\r\n\r\n" .
"Best wishes\r\n" .
"The Publisher";
if (wp_mail($email_address, $subject, $body, "From: \"BLOG TITLE\" <address.of#the-blog>")) { }
}
add_action('publish_post','announce_post');
As it is the function works well, but of course I would replace the SOMEONE with the actual post's author name. And I don't manage to retrieve that.
Neither get_the_author($post_id), get_post_meta($post_id, 'author_name', true) nor anything else I tried and can't recall worked. Everything just returned "".
So what is the correct way to retrieve the post author's name, given a post id?
get_the_author() is a (perhaps misleading) function that is intended for use in the loop. It's only parameter is now deprecated. It's also worth noting that author data is not stored as post meta, so any get_post_meta attempts will be in vain.
You should in fact use get_the_author_meta( 'display_name', $author_id ). I would suggest accepting the second argument in your hook, which is the $post object, to obtain the author ID:
function announce_post( $post_id, $post ) {
$name = get_the_author_meta( 'display_name', $post->post_author );
}
add_action( 'publish_post','announce_post', 10, 2 );

How to sendmail via php with dynamic url

I have a big problem! I need to track what the users are doing on my site. As a way to resolve it I crated a sendmail function in order to send me an email every time a user clicks on a button. The code is this:
<div class="buy">
<a onclick="target='_blank'" href="<?php echo $this->product['from'];?>">
<?php
// The message
$message = "A new buy";
$link = "<?php echo $this->product['from'];?>";
// Send
mail('xxx#mail.com', '#buy PRODUCT', $message, $link);
?>
<img src="http://xxx.com/data/images/xxx.jpg" alt="Comprar" />
</a>
</div>
The message I receive is
"A new buy
**<?php echo $this->product['from'];?>**"
And it should look like:
"A new buy
http://www.xxxx.com"
Anyone can help me with this problem?
Ok, then try this:
$message = "A new buy ".PHP_EOL.PHP_EOL;//add two new lines for plaintext message
$message .= $this->product['from']; //add link to the end of message
// Send
mail('xxx#mail.com', '#buy PRODUCT', $message); //no need for fourth parameter
Read further:
http://php.net/manual/en/function.mail.php
And for easy e-mailing use phpmailer:
http://code.google.com/a/apache-extras.org/p/phpmailer/
Instead of:
$link = "<?php echo $this->product['from'];?>";
use
$link = $this->product['from'];

Categories