I recently took over a project for a client which is website built in wordpress and java script. The previous developer did not comment on their code so I have taken some time to decipher it.
The site uses woocommerce as the online shop. The client has requested that when a user makes a payment then the subsequent thank you screen displays an animated gif saying thank you.
Inserting the gif on the standard woocommerce checkout page is fine and works. The client however wants it displayed after the purchase on the thank you page which is created in code. The code is displayed below:
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p><?php esc_html_e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', "wp-experts" ); ?></p>
<p><?php
if ( is_user_logged_in() )
esc_html_e( 'Please attempt your purchase again or go to your account page.', "wp-experts" );
else
esc_html_e( 'Please attempt your purchase again.', "wp-experts" );
?></p>
<p>
<?php esc_html_e( 'Pay', "wp-experts" ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php esc_html_e( 'My Account', "wp-experts" ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', "wp-experts" ), $order ); ?></p>
<ul class="order_details pull-left">
<li class="order">
<?php esc_html_e( 'Order Number:', "wp-experts" ); ?>
<strong><?php echo ''.$order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php esc_html_e( 'Date:', "wp-experts" ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php esc_html_e( 'Total:', "wp-experts" ); ?>
<strong><?php echo ''.$order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php esc_html_e( 'Payment Method:', "wp-experts" ); ?>
<strong><?php echo ''.$order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
CLICK HERE TO GET STARTED!
<div class="clear"></div>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', "wp-experts" ), null ); ?></p>
I have searched on google for how to display a gif in php.
The gif is uploaded on my serve in the images sub-directory of the theme
I have used ideas from stackoverflow like
$file = 'Camel-continuous-1.gif'
header('Content-type: image/gif');
readfile($file);
but this just crashes the web page. I placed this after the payment method line in the code above.
Any ideas? Thanks in advance
I am not able based on the code sniplet to tell where to insert it, but if you
<?php
//supposing the gif is in the same folder
$file = 'Camel-continuous-1.gif';
echo "<img src=\"".$file."\">";
?>
More short you could say it this way:
<?php='<img src="/gifs/Camel-continuous-1.gif" >'?>
Or more simple if you want to use the short open tag
<?='<img src="/gifs/Camel-continuous-1.gif" >'?>
have fun
Like #flomei I'm not sure I understand what you want, but if you just want the gif somewhere near the "Thank You" text you can just echo it in php. This will put it above the text "Thank you. Your order has been received":
<?php if ( $order->has_status( 'failed' ) : ?>
<?php // deleted your existing code. ?>
<?php else : ?>
<?php echo '<img src="Camel-continuous-1.gif"> ?>
<?php // more deleted code. ?>
<?php endif; ?>
this did not work for you because you mixed up Quotes. If you use double quotes to delimit a string you must either backslash it or use simple quotes inside.
In a similar way you must use double quotes if you delimit the string with simple quotes.
<?php
// this outputs a error
$file = '/uploads/2018/07/Camel-continuous-2.gif';
echo "<img width="251" height="243" src=\"".$file."\">";
?>
this will work for you on any php version. It is the clean method using backslashed quotes inside the quotes
<?php
$file = "/uploads/2018/07/Camel-continuous-2.gif";
echo "<img width=\"251\" height=\"243\" src=\"".$file."\">";
?>
also this will work for you on some php versions. (using double quotes inside simple quotes
<?php
$file = '/uploads/2018/07/Camel-continuous-2.gif';
echo '<img width="251" height="243" src="'.$file.'">';
?>
also this will work for you depending on your php version. using simple quotes inside double quotes
<?php
$file = "/uploads/2018/07/Camel-continuous-2.gif";
echo "<img width='251' height='243' src='".$file."'>";
?>
Related
Here is a piece of my code.
<div class="thim-course-grid">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="lpr_course <?php echo 'course-grid-' . $columns; ?>">
**<div class="course-item" onmouseover="hide_card('<?= get_the_ID()?>');" onmouseout="show_card('<?= get_the_ID()?>');">**
<div class="course-thumbnail" id="course-thumbnail-<?= get_the_ID()?>">
<a href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>">
<?php echo thim_get_feature_image( get_post_thumbnail_id( get_the_ID() ), 'full', $thumb_w, $thumb_h, get_the_title() ); ?>
</a>
<?php do_action( 'thim_inner_thumbnail_course' ); ?>
<!-- <a class="course-readmore"
href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html__( 'Read More', 'eduma' ); ?></a> -->
</div>
<div class="thim-course-content" id="thim-course-content-<?= get_the_ID()?>">
<?php learn_press_courses_loop_item_instructor();
the_title( sprintf( '<h2 class="course-title">', esc_url( get_permalink() ) ), '</h2>' );
?>
<?php if ( class_exists( 'LP_Addon_Coming_Soon_Courses_Preload' ) && learn_press_is_coming_soon( get_the_ID() ) ): ?>
<div class="message message-warning learn-press-message coming-soon-message">
<?php esc_html_e( 'Coming soon', 'eduma' ) ?>
</div>
<?php else: ?>
<div class="course-meta">
<?php learn_press_courses_loop_item_instructor(); ?>
<?php thim_course_ratings(); ?>
<?php learn_press_courses_loop_item_students(); ?>
<?php thim_course_ratings_count(); ?>
<?php learn_press_courses_loop_item_price(); ?>
</div>
<?php learn_press_courses_loop_item_price(); ?>
<?php endif; ?>
<div class="course-readmore">
<?php esc_html_e( 'Read More', 'eduma' ); ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
On the 4th line, I wanted to truncate the course maps on mouse over, so that all the part of the map at the bottom of the image disappears, only to reappear when there is no more flyover. The result obtained is different from what I wanted.
I put the link to the site to see: www.formatine.com
And here is the JS part that I added as well.
function hide_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'none';
document.getElementById('course-thumbnail-'+id).innerHTML = "<?= wp_oembed_get( $media_intro ) ?>";
}
function show_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'block';
document.getElementById('course-thumbnail-'+id).style.display = 'block';
}
Do you have an idea for me please? Thank you.
Don't use "display: none" because once it has it, the element "disappears".
It is better for you, to then, if you want to include a video instead of the card, for example, do it by having both, one behind the other by default, if you "mouseover" display the code INSIDE of one, and on "mouseout", display the other.
<div class="mycard">
<div class="myinfoforthevideo"></div>
<div class="myvideo"></div>
</div>
You controll the events on mycard class, and hide myinfoforthevideo by default, on "mouseover", hide it and show then myvideo, and on "mouseout" hide myvideo and show myinfoforthevideo
You're hidding everything so now since its a width: 0/height: 0 let's say, you don't have any place to do the mouseover now.
Extra:
You can try flip cards as another option, like this:
https://codepen.io/Aoyue/pen/pLJqgE
So I want to remove the billing address from the thank you page. I am using wordpress and have the theme Impreza.
I have targeted the .woocommerce-customer-details and set to display: none; which worked on the google inspector mode but saved and refreshed and it still shows up. And I have checked the woo-commerce template files and found the order-details-customer.php is generating the information. I added a class to remove that section but it still shows up.
Woocommerce thank you page
In theme find a folder named woocommerce if not exist then Create folder:
Copy this file
/wp-content/plugins/woocommerce/templates/checkout/thankyou.php
and paste it into your active theme directory something like this
/wp-content/themes/activetheme/woocommerce/checkout/thankyou.php
And remove this
<ul class="woocommerce-thankyou-order-details order_details">
<li class="order">
<?php _e( 'Order Number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
<div class="clear"></div>
and also remove this
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
I am new to Wordpress development and am trying to install a traffic junky tracking code on the thankyou.php page.
My attempt has failed so far and I think it boils down to not understanding PHP well enough.
The two tracking codes from trafficjunky that were available were HTML or PHP
HTML:
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
PHP:
<?php
$randomNumber = time() . mt_rand(1000, 9999999);
$currentPage = substr($_SERVER["REQUEST_URI"], 0, 255);
?>
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=<?=$randomNumber ?>&epu=<?=$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
I tried to install the HTML version after the order processes under some PHP code on the thankyou.php WooCommerce template:
**<?php else : ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
<li class="woocommerce-order-overview__order order">
<?php _e( 'Order number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="woocommerce-order-overview__date date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
</li>
<?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
<li class="woocommerce-order-overview__email email">
<?php _e( 'Email:', 'woocommerce' ); ?>
<strong><?php echo $order->get_billing_email(); ?></strong>
</li>
<?php endif; ?>
<li class="woocommerce-order-overview__total total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->get_payment_method_title() ) : ?>
<li class="woocommerce-order-overview__payment-method method">
<?php _e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
</li>
<?php endif; ?>
</ul>
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
<?php else : ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
<?php endif; ?>
</div>**
This led to order errors so i am trying to figure out how to add the PHP version of the tracking code safely without throwing errors.
Any help would be appreciated.
Thank you for the replies, I have set up the function in functions.php as instructed but I am still having trouble getting the tracking code to fire. Here is my current code:
add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );
function tracking_code_thankyou($order_id){
$random_number = time() . mt_rand(1000, 9999999);
$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
?>
<em>Your tracking code just below (for testing)</em>
<img id="1000145711_cpa_testing" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=<?=$randomNumber ?>&epu=<?=$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
<?php
}
}
You can try adding the php tracking code inside the header.php (before the end of the head tag) or footer.php (before the end of the body tag). You need to get the id of the page if you want it to run exclusively on that page only.
Do something like this
if(is_page(yourpageidhere)):
//paste the tracking code here
endif;
UPDATED
Instead of overriding the thankyou.php template as you can see its source code there is this line:
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
Which means that you can use this woocommerce_thankyou action hook with a custom function, to output anything in this template line. First get the template clean of your code...
Also I have corrected your code in the image link, as it was not correct. You should use the following code in the function.php file of your active child theme or active theme:
add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );
function tracking_code_thankyou( $order_id ) {
$random_number = time() . mt_rand(1000, 9999999);
$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
$url = "https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=$randomNumber&epu=$currentPage&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]";
echo '<em>Your tracking code just below (for testing)</em>
<img id="1000143661_tester" src="'.$url.'" width="1" height="1" border="0" />';
}
It will output your code just after customers details at the end of the order-received page…
I've tried to edit the thankyou.php file in woocommerce to include some new text, but it keeps on showing the default message. I am not familiar with what anything means in php, but this is what I've been trying:
<?php
/**
* Thankyou page
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.2.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( $order ) : ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce' ); ?></p>
<p><?php
if ( is_user_logged_in() )
_e( 'Please attempt your purchase again or go to your account page.', 'woocommerce' );
else
_e( 'Please attempt your purchase again.', 'woocommerce' );
?></p>
<p>
<?php _e( 'Pay', 'woocommerce' ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php _e( 'My Account', 'woocommerce' ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Your shirt order has been received and will be at your doorstep in approximately 4 weeks. Thanks again for your support (and general badassery)!', 'woocommerce' ), $order ); ?></p>
<ul class="order_details">
<li class="order">
<?php _e( 'Order:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
<div class="clear"></div>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Your shirt order has been received and will be at your doorstep in approximately 4 weeks. Thanks again for your support (and general badassery)!', 'woocommerce' ), null ); ?></p>
The best way to do this would be to filter the WC thank you message:
add_filter( 'woocommerce_thankyou_order_received_text', 'd4tw_custom_ty_msg' );
function d4tw_custom_ty_msg ( $thank_you_msg ) {
$thank_you_msg = 'This is your new thank you message';
return $thank_you_msg;
}
Perhaps your theme is overriding your thank you template file. As a general rule you should never edit the plugin directly. Instead move the thankyou.php to your theme. Move this file to wp-content/themes/yourtheme/woocommerce/checkout/thankyou.php. More information it the documentation here.
I`d like to do this:
<a href="...">
<img src="..." />
<h5>Older Post</h5>
<p>Titel</p>
</a>
My code
<?php next_post_link('%link', "$prevthumbnail __('<h5>Older Post</h5>'),
<p>%title</p>", TRUE); ?>
but doesn´t work at all. I´ve some syntax problems to combine PHP (WordPress translation) and HTML:
Thanks for your help
Ogni
--- UPDATE ---
<?php next_post_link('%link', "$nextthumbnail", TRUE); ?>
<?php next_post_link('%link', __("<span class='header'>Older post</span>", "SCNR"), TRUE); ?>
<?php next_post_link('%link', "<span>%title</span>", TRUE); ?>
This is untested, but it should work for what you need. Instead of using the next_post_link() function which was really meant for simpler links, we're building the link on our own.
<?php
// Gets the ID of the next post in the same term
$next_post = get_next_post( true );
// If that ID exists...
if ( ! empty( $next_post ) ) :
?>
<a href="<?php echo get_permalink( $next_post ); ?>">
<?php echo get_the_post_thumbnail( $next_post ); ?>
<h5><?php _e( 'Older Post', 'textdomain' ); ?></h5>
<p><?php echo get_the_title( $next_post ); ?></p>
</a>
<?php endif; ?>
You need some serious help, try this instead.
<?php
//connect to database and set variables or whatever
$link = "http://foo.bar";
$prevthumbnail = "img/foo.png";
$title = "The Foo Bar";
//then print this...
echo '<img src="'.$prevthumbnail.'" /><h5>Older Post</h5><p>'.$title.'</p>';
?>