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;
Related
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]).
I'll start by saying I'm fairly new to coding so I'm probably going about this the wrong way.
Basically I've got the below php function that changes urls to the page title of the url instead of a plain web address. So instead of www.google.com it would appear as Google.
<?php
function get_title($url){
$str = file_get_contents($url);
if(strlen($str)>0){
$str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case
return $title[1];
}
}
?>
This is great but to implement this I have to use the below code.
echo get_title("http://www.google.com/");
However this just works on a predefined URL. What I have set up on my site at the moment is a shortcode in a html widget.
<a href='[rwmb_meta meta_key="link_1"]'>[rwmb_meta meta_key="link_1"]</a>
This shortcode displays a url/link that is input by the user in the backend of Wordpress and displays it on the frontend as a link. However I want to apply the get_title function to the above shortcode so instead of the web address it shows the page title.
Is this possible?
Thanks in advance.
for name of a url from a link you can use parse_url($url, PHP_URL_HOST);
easier way would be to have an array of links for example
$links[] = 'some1 url here';
$links[] = 'some2 url here';
then just loop your $links array with the function.
foreach($links as $link)get_title($link);
https://metabox.io/docs/get-meta-value/
try:
$files = rwmb_meta( 'info' ); // Since 4.8.0
$files = rwmb_meta( 'info', 'type=file' ); // Prior to 4.8.0
if ( !empty( $files ) ) {
foreach ( $files as $file ) {
echo $file['url'];
}
}
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/
I have here a function that creates a clickable link:
function makeClickableLinks($text) {
$notIncludedonLink = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&##\/%?=~_|$!:,.;]*[A-Z0-9+&##\/%=~_|$]/i', '', $text); // removing not included on the link
$urlLink = str_replace($notIncludedonLink,'',$text);
$finalText = str_replace($urlLink,''.$urlLink.'',$text);
return $finalText;
}
But instead of returning plain clickable link:
http://docs.google.com/
it displays:
http://docs.google.com/
I tried using htmlentities but it doesn't work.
Here's a JS code that sends data to server:
function checkNewLink() {
var latestId = $("input[name=latestLink]").val();
$('.newReply').load("links/ajax.php?action=newreply&msgid=<?php echo $msgId; ?>&latestid=" + latestId);
}
setInterval("checkNewLink()", 200);
where latestId contains the inputted link. It will be sent to ajax.php. Every 200 ms, it will check if there are new inputted link.
<?php
function makeClickableLinks($text){
return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9#:%_+.~#?&;//=]+)!i', '$1', $text);
}
echo makeClickableLinks('test http://docs.google.com/ test');
output code (http://codepad.org/EZE1HFZ4)
test http://docs.google.com/ test
AFTER UPDATE
change
setInterval("checkNewLink()", 200);
to
setInterval(function(){ checkNewLink() }, 200);
read setInterval() Method
I tried modifying a chat script.
(The original script is from Eliza Witkowska link.) I mainly tried converting some text into emoticons. So far I can only convert text into emoticons properly.
But, the text gets converted to icons only when I send the message but doesn't get converted when I receive the message on another browser (I'm using sessions so I have to use another browser) unless a refresh or I send a message from that another browser.
To be more clear, suppose I have logged in to an a/c from chrome and another a/c from Firefox; when I send a message from Chrome, the specified characters get converted into icons but only the characters show up on firefox until a page refresh or until a new message is sent from firefox.
db.php
function check_changes(){
$result = $this->db->query('SELECT counting FROM news WHERE id=1');
if($result = $result->fetch_object()){
return $result->counting;
}
return 0;
}
function get_news(){
if($result = $this->db->query('SELECT * FROM news WHERE id<>1 ORDER BY add_date DESC LIMIT 50')){
$return = '';
while($r = $result->fetch_object()){
$timing=explode(" ", $r->add_date);
$return .= $r->title;
$return .='<p>'.$timing[1].' on '.$timing[0].'</p><hr/> ';
//$return .= '<hr/>';
}
return $return;
}
}
profile.php
function parseSmiley($text){
//Smiley to image
$smileys=array('o:)'=>'angel.gif', ':3'=>'colonthree.gif', 'o.O'=>'confused.gif', ":'("=>'cry.gif', '3:)'=>'devil.gif', ':('=>'frown.gif', ':O'=>'gasp.gif', '8)'=>'glasses.gif', ':D'=>'grin.gif', ">:("=>'grumpy.gif', '<3'=>'heart.gif', '^_^'=>'kiki.gif', ':*'=>'kiss.gif', ':v'=>'pacman.gif', ':)'=>'smile.gif', '-_-'=>'squint.gif', '8|'=>'sunglasses.gif', ':p'=>'tongue.gif', ':/'=>'unsure.gif', '>:O'=>'upset.gif', ';)'=>'wink.gif');
//Now you need to find and replace
foreach($smileys as $smiley=>$img){
$smiley = preg_quote($smiley, '/');
$text = preg_replace( "#(?<=\s|^)(?:$smiley)((?=\s|$))?#i", '<img src="emotions-fb/'.$img.'">', $text);
}
//Now only return it
return $text;
}
$print= parseSmiley($db->get_news());
<div id="message_short" data-counter="<?php echo (int)$db->check_changes();?>">
<?php echo wordwrap($print, 25, "\n", true);?>
</div>
<div id="message_long" data-counter="<?php echo (int)$db->check_changes();?>">
<?php echo wordwrap($print, 35, "\n", true);?>
</div>
Be sure to wrap get_news() everywhere with parseSmiley().
As I can see from the link provided, there is a checker.php in which $db->get_news() should be replaced with parseSmiley($db->get_news())