I am new to WooCommerce. After the payment is made I am redirected to another PHP file (testpayresult.php). From this file, I need redirect to the Thankyou page in WooCommerce. How do I achieve this?
Sending the order details to the payment gateway API:
echo '<script src="https://test.oppwa.com/v1/paymentWidgets.js?checkoutId='. $responseData->id . '"></script>';
echo '<form action="/wp-content/plugins/woo-payment-gateway-for-taurus-datafast/testpayresult.php" class="paymentWidgets" data-brands="VISA MASTER AMEX DINER DISCOVER"> </form>';
echo '<form action="/wp-content/plugins/woo-payment-gateway-for-taurus-datafast/testpayresult.php" class="paymentWidgets" data-brands="VISA MASTER AMEX DINER DISCOVER"> </form>';
The testpayresult.php file:
<?php
echo "Payment Over";
echo "<br />POST<br />";
$resourcePath = '/v1/checkout/' . $_GET["id"] . "/payment"; //$_GET["resourcePath"];
echo "<br /> Resource Path: " . $resourcePath;
$entityId = $_GET["id"];
echo "<br /> Entity Id: " . $entityId;
//echo "<br /><br /> Thanks Page URL: " . get_option( 'woocommerce_thanks_page_id' );
echo "<br />";
function check_transaction_status($presourcePath, $pentityId)
{
$url = "https://test.oppwa.com" . $presourcePath;
$url .= "?entityId=8ac7a4ca7402389d0174023e6b6b001c";
echo "<br />URL: " . $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:Bearer OGE4Mjk0MTg1YTY1YmY1ZTAxNWE2YzhjNzI4YzBkOTV8YmZxR3F3UTMyWA=='
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // this should be set to true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $responseData;
}
$response = check_transaction_status($resourcePath, $entityId);
How do I get the order Id in the testpayresultfile.php?
It is called by the submit in the generate_taurusdatafast_form($order) function in the wooshop-taurus-datafast.php file
Code in Github
Related
I've a code snippet that builds an html email and send it towards a batch of users.
The email can contain one or multiple attachments.
Previously, my code was working fine, but since a few months the attachments are not sent anymore. More concrete, wordpress mail loggers tell me:
An attachment was sent but it was not in the media library
Below the code that handles the attachment, the rest of the email is working fine, headers are set to text/html
If I dump the path of the attachment in the mail an example is:
/home/lwk/domains/lintsewindklievers.be/public_html/wp-content/uploads/2022/10/CaveTriathlon_2021_111_RUN.gpx
I've no idea why this isn't working anymore..
Someone who might know what's going wrong?
function sentMail($rit, $maillist){
global $wpdb;
global $today;
$today = new DateTime();
$today = $today->format('Y-m-d');
$checkMail = FALSE;
$attachments = array();
// components for our email
$subject = "LWK Rit | ".date("d-m-Y h:i", strtotime($rit->datum_rit))." | ".$rit->post_title;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "'Content-Type: text/html; charset=UTF-8'";
//$headers .= "'Content-type: multipart/mixed; charset=iso-8859-1";
$headers .= "'From: De Lintse Windklievers <mail#lintsewindklievers.be>'";
$headers .= "'Reply-To: secretaris#lintsewindklievers.be'";
$message = '<html><body>';
$message .= '<img width="150" height="78" src="https://lintsewindklievers.be/wp-content/uploads/2021/05/Logo-LWK-scaled.jpg" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Title</strong> </td><td>" . $rit->post_title . "</td></tr>";
$message .= "<tr><td><strong>Datum</strong> </td><td>" . date("d-m-Y h:i", strtotime($rit->datum_rit)) . "</td></tr>";
$message .= "<tr><td><strong>Afstand</strong> </td><td>" . $rit->afstand . "</td></tr>";
$message .= "<tr><td><strong>Organistie</strong> </td><td>" . $rit->organisatie . "</td></tr>";
$message .= "<tr><td><strong>Vertrekplaats:</strong> </td><td>" . $rit->vertrekplaats . "</td></tr>";
$message .= "<tr><td><strong>Stopplaats:</strong> </td><td>" . $rit->stopplaats . "</td></tr>";
$message .= "<tr><td><strong>Opmerkingen:</strong> </td><td>" . $rit->opmerkingen . "</td></tr>";
if (isset($rit->gpx_route)){
$aGPX = unserialize($rit->gpx_route);
foreach ( $aGPX as &$file){
$url = wp_get_attachment_url( $file );
$name = get_the_title($file);
$sGPX = "<a href='". $url ."'>" . $name . ".gpx</a>\n\n";
$message .= "<tr><td><strong>GPX:</strong> </td><td>" . $sGPX . "</td></tr>";
//echo $url;
$parsed = parse_url( wp_get_attachment_url( $file ) );
$urlx = dirname( $parsed [ 'path' ] ) . '/' . rawurlencode( basename( $parsed[ 'path' ] ) );
$urlx = substr($urlx, strpos($urlx, '/', 1));
array_push($attachments, WP_CONTENT_DIR . $urlx );
//$message .= "<tr><td><strong>GPX attachment:</strong> </td><td>" . WP_CONTENT_DIR . $urlx . "</td></tr>";
}
}
$message .= "</table>";
$message .= "</body></html>";
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
foreach( $maillist as $recepient ){
if(wp_mail( $recepient, $subject, $message, $headers, $attachments )){
$checkMail = TRUE;
}else{
$checkMail = FALSE;
}
}
if($checkMail){
$wpdb->update('wp_custom_ritten', array('notif_mail'=>$today), array('id'=>$rit->ID));
}
// Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578
remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
}
function wpdocs_set_html_mail_content_type() {
return 'text/html';
}
I have got a comment from someone superior to me who wants me to escape some comment in two php snippets which I have posted below. The problem is I don't know how to do that. Can anyone help me by modifying the snippets.
Comment I got:
Comment #1:
Validate and/or sanitize untrusted data before entering into the database. All untrusted data should be escaped before output.
Code Snippet #1:
<?php
if ( get_header_image() && !('blank' == get_header_textcolor()) ) {
echo '<div class="site-branding header-background-image" style="background-image: url(' . get_header_image() . ')">';
} else {
echo '<div class="site-branding">';
}
?>
Code Snippet #2:
<?php
printf(
/* translators: %1$s = text link: sangeet, URL: http://wordpress.org/themes/sangeet/, %2$s = text link: Kiran Kumar Dash, URL: https://twitter.com/TheKiranDash */
__( 'Theme: %1$s by %2$s', 'sangeet' ),
'' . esc_attr( 'sangeet', 'sangeet' ) . '',
'' . esc_attr__( 'Kiran Kumar Dash', 'sangeet' ) . '' );
?>
Comment #2:
esc all get_permalink() in content.php
Code snippet #3
<?php
if ( !is_single() ) {
echo '<div class="index-box">';
if ( has_post_thumbnail()) {
echo '<div class="small-index-thumbnail clear">';
echo '<a href="' . get_permalink() . '" title="' . __('Read ', 'sangeet') . get_the_title() . '" rel="bookmark">';
echo the_post_thumbnail('index-thumb');
echo '</a>';
echo '</div>';
}
}
?>
My approach:
I used esc_url to esc the get_permalink() in the snippet. Shall I use esc_all? Or esc_url is just fine.
<?php
if ( !is_single() ) {
echo '<div class="index-box">';
if ( has_post_thumbnail()) {
echo '<div class="small-index-thumbnail clear">';
echo '<a href="' . esc_url(get_permalink()) . '" title="' . __('Read ', 'sangeet') . get_the_title() . '" rel="bookmark">';
echo the_post_thumbnail('index-thumb');
echo '</a>';
echo '</div>';
}
}
?>
As requested:
PS. I didnt write this, only advanced it.
Usage:
$user = sanctify($_GET['user']);
Function:
function sanctify($data){
// Fix &entity\n;
$data = str_replace(array('&','<','>'), array('&','<','>'), $data);
$data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
$data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
$data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
// Remove javascript: and vbscript: protocols
$data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data);
// Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data);
// Remove namespaced elements (we do not need them)
$data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);
$data = str_replace('"','',str_replace("'","",$data));
do{
// Remove really unwanted tags
$old_data = $data;
$data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
}
while ($old_data !== $data);
// we are done...
return $data;
}
I'm stuck on a problem and thought maybe I'm missing something basic. I'm making a function in WordPress that lists posts with a publish date of less than one month from "now". I do this by subtracting 2419200 (30 days) from the current time, using time(). Then I get posts which are > 30 days ago. However, my function interprets this range incorrectly and only serves up posts which are within a range of 2 weeks!
There is a lot going on in this function in addition to this problem, so I apologize, but follow the variables $range, $limit, and $publish_date for this issue. Notice that for testing purposes I set my variable to "monthly" manually at the start.
function send_archive() {
$range = 'monthly';
$now = time();
switch ($range) {
case 'monthly' :
$limit = ($now - 2419200); // 30 days
break;
case 'weekly' :
$limit = ($now - 604800);
break;
case 'daily' :
$limit = ($now - 86400);
break;
}
$post_types = get_post_types();
$posts = get_posts(array('post_type' => $post_types));
$all_users = get_users();
foreach ($all_users as $user) {
$excluded = excluded_admin( $user->user_login );
echo 'excluded is: ' . $excluded . '<br />';
echo 'user_login is: ' . $user->user_login . '<br />';
if ( $excluded != 'excluded' ) {
$frequency = get_user_meta($user->ID, 'iw_notify_frequency', true);
echo 'frequency is: ' . $frequency . '<br />';
echo 'Range is: ' . $range . '<br />';
echo 'Limit is: ' . date('D, d M Y H:i:s',$limit) . '<br />';
$posts_in_range = '';
$counter = 0;
$to = '';
$subject = '';
$headers = '';
if ($frequency == $range) {
$posts_in_range = get_option('iw-notify-greeting');
$posts_in_range .= '<p>' . strtoupper($range) . ' digest of posts from the City of Mukilteo</p>';
foreach ($posts as $post) {
$published_date = strtotime( $post->post_date_gmt );
$posts_in_range .= 'published_date: ' . $published_date. '<br />';
$posts_in_range .= 'limit: ' . $limit . '<br />';
$posts_in_range .= 'title: ' . $post->post_title . '<br />';
if ($published_date > $limit ) {
$match = has_user_selected_terms($user->ID, $post->ID);
if ($match != '') {
$headers = 'Content-type: text/html;charset=utf-8' . "\r\n";
$posts_in_range .= $post->post_title;
$posts_in_range .= ' - published ' . date('M, d', $published_date) . '<br />';
$posts_in_range .= $post->post_excerpt . '<br />';
$posts_in_range .= get_permalink($post->ID);
$posts_in_range .= '<br /><br />';
$counter++;
}
}
}
}
$posts_in_range .= get_option('iw-notify-unsubscribe') . '<br />----<br />';
if ( $counter != 0 ) {
$to = $user->user_email;
$subject = ucfirst($range) . ' archive from the City of Mukilteo';
$headers = 'Content-type: text/html;charset=utf-8';
$headers .= 'From: ' . get_option('from-name') . '<' . get_option('from-email') . '>' . "\r\n";
$content = $posts_in_range;
wp_mail($to, $subject, $content, $headers);
echo "Email sent to " . $user->display_name . '<br />';
echo $to . '<br />';
echo $subject .'<br />';
echo $headers . '<br />';
echo $posts_in_range . '<br />';
//echo $user->display_name . '<br />';
//echo $posts_in_range;
}
}
}
}
Instead of going all over your posts you can run a query using a date range
$args = array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'after' => '1 month ago',
)
),
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
//DO YOUR STUFF WITH THE RESULTS
This query should return the post created in the last month.
More info about Date Parameters
I have a some trouble with understanding in uploading and sending attachment.
For example:
$zip_code = $_POST['zip_code'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$attachments = '';
if (!empty($_FILES['attachment']['tmp_name'])) {
$path = $_FILES['attachment']['name'];
if (copy($_FILES['attachment']['tmp_name'], $path)) $attachments = $path;
}
$subject = 'You have message from ' . get_bloginfo('name');
$message = '<table width="100%" cellspacing="0" cellpadding="5" border="0">';
$message .= '<tr><td width="150px"><b>Zip Code:</b></td><td>' . $zip_code . '</td></tr>';
$message .= '<tr><td width="150px"><b>Phone:</b></td><td>' . $phone . '</td></tr>';
$message .= '<tr><td width="150px"><b>Email:</b></td><td>' . $email . '</td></tr>';
$message .= '<tr><td width="150px"><b>Attachments:</b></td><td>' . $attachments . '</td></tr>';
$message .= '</table>';
//php mailer variables
$to = get_option('admin_email');
$headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Disposition: attachment; filename = \"" . $attachments . "\"\n\n";
$sent = wp_mail($to, $subject, $message, $headers, $attachments);
This code work not correctly. Email and attachment sending correctly, but file upload in root directory. And when I upload the same files, new file overwrite old file. I don't understand how I can add some hash tag to file name.
Maybe U can help me? Any ideas or where I can read how to resolve this issue.
Thanks!
What is not working? To help you find out what is not working, try this:
$zip_code = $_POST['zip_code'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$attachments = '';
if (!empty($_FILES['attachment']['tmp_name'])) {
$path = $_FILES['attachment']['name'];
if (copy($_FILES['attachment']['tmp_name'], $path)) $attachments = $path;
}
$subject = 'You have message from ' . get_bloginfo('name');
$message = '<table width="100%" cellspacing="0" cellpadding="5" border="0">';
$message .= '<tr><td width="150px"><b>Zip Code:</b></td><td>' . $zip_code . '</td></tr>';
$message .= '<tr><td width="150px"><b>Phone:</b></td><td>' . $phone . '</td></tr>';
$message .= '<tr><td width="150px"><b>Email:</b></td><td>' . $email . '</td></tr>';
$message .= '<tr><td width="150px"><b>Attachments:</b></td><td>' . $attachments . '</td></tr>';
$message .= '</table>';
//php mailer variables
$to = get_option('admin_email');
$headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Disposition: attachment; filename = \"" . $attachments . "\"\n\n";
echo 'Headers: . $headers . '<br>/r/n';
echo 'To: ' . $to .'<br>/r/n';
echo 'Subject: ' . $subject . '<br>/r/n';
echo 'Message: ' . $message . '<br>/r/n';
echo 'Image: <img src="' . $attachments .'" />';
// $sent = wp_mail($to, $subject, $message, $headers, $attachments);
You'll be able to see what is missing if there is anything missing, and you'll be able to rectify your code this way.
I have been trying to echo the post thumbnail for worpress using the string and the function but it doesnt work.
Here is the template i am trying to show it.
if ($favorite_post_ids):
$favorite_post_ids = array_reverse($favorite_post_ids);
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
echo "<li>";
echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title . "</a> ";
echo '<img src="'.get_the_post_thumbnail(array(55,55)).'" />';
wpfp_remove_favorite_link($post_id);
echo "</li>";
First parameter of get_the_post_thumbnail() is the post ID, not the thumbnail size